Tag Info

New answers tagged

0

I am not familiar with C++ much, so I will describe the concept in C#, which you probably should have a look at as it's much simpler language to work with. I also don't understand the details of your question, which explains the negative votes your questions gets. However, I do understand the question that is in your title, and so I will explain the concept ...


0

We should not forget that the whole is greater than the sum of its parts. I could imagine a situation where a user exists and his phone number is unknown.. Is the user an instance of ICallable? To be 'callable' and to be 'a user' are two different things. So, design of your interfaces should reflect this notion. I think that your question is not about ...


1

One possible solution: Upon execution, create a temporary file and store the status in it. Useful to keep logs as well. Delete the file every time new execution starts and you no longer need it.


0

'Program to an interface' is a general, language-independent statement. With languages like C# and Java that have an explicit language feature called interface, this can lead to confusion. The thing to remember is that both languages have at least two ways of defining interfaces; explicitly, with a keyword implcitly, by taking a class and making only the ...


0

I've also had concrete classes implement a handful of interfaces, but the classes have been mediators that delegate their behavior to single-responsibility classes that each satisfy a single interface. The mediation class itself has little behavior outside of determining how the individual modules will interact and be utilized. That mediation becomes its ...


1

It's not wrong. It might be a hint that your class is too big for its shoes in the first place and you should refactor it, but that has nothing to do with programming against interfaces. If you follow the principle that complex functionality should deal with interface types rather than concrete types, then your concrete class must wear all those interface ...


2

For values closely related to pointers (and thus, to the amount of addressable memory) such as buffer sizes, array indexes, and Windows' lParam, it makes sense to have an integer type with an architecture-dependent size. So, variable-sized types are still useful. This is why we have the typedefs size_t, ptrdiff_t, intptr_t, etc. They have to be typedefs ...


2

Generally speaking, an Exception is suited for this and the best practice you should follow is: "If a method can't do it's job, it should throw an exception." Understandably, you may want execution flow to continue without exceptions. The .NET space handles this fairly well and provides a convention for methods that don't throw exceptions. Methods that ...


3

First of all this method is not unit testable. There is nothing in the code you quoted which prevents it from being covered by unit tests. The presence of try/catch is irrelevant: You can test the situation where there is no error and check whether the side effects of this method correspond to the expectations. You can also test the situation where ...


1

From my point of view the method "CanBeAdded" should neither be in the item, nor in a special rulter. It should be in the list itself. Therefore: if list.CanAdd(item) ... end The List implementation then should have a set (probably implemented as list) of rules, that define whether an item can be added. function CanAdd(item) As Boolean for each ...


7

He doesn't mean little IDE utilities that create boilerplate for you, which you must modify. He's referring to more comprehensive code generation that you shouldn't have to touch. You make changes to the higher level and regenerate. The canonical Unix example would be Yacc, which uses a high-level grammar to generate complex parsing code. Other examples: ...


0

In this case, it is perfectly okay to suppress the unchecked cast warning. It's an unchecked cast because E is not known at runtime. So the runtime check can only check the cast up to Object[] (the erasure of E[]), but not actually up to E[] itself. (So for example, if E were Integer, then if the object's actual runtime class was String[], it would not be ...


0

If the value is just that - the value, stick to using it as a field on another object. Mass and Speed are 2 different things indeed, but the fact that I created a separate type for each doesn't really mean I wouldn't mix the two up when I create new instances of those objects - in other words - NO, simple types are simple for a reason and you shouldn't ...


0

I would first check if there is a method named "empty", "isEmpty" or similar. The reason: Your check MyArray.Length < 1 determines the length of the array, even though you are not interested in the length at all, only in the fact that it is 0 or not 0. For some instances with a huge length, determining the length might be quite time consuming, while ...


1

It is not unusual to have several keys in a table and there's nothing fundamentally wrong with that. If a table has more than one key then the choice of "primary" key is unimportant - or only as significant as you want to make it. Your boss is correct that it is usually a good idea for every SQL Server table to be clustered. Guids don't make for good ...


0

I'm in favor of the micro domain types as @Miki describes them. I've done both and the code that has the custom types is easier to maintain than the code using primitive types, especially in large projects. Making changes and/or finding uses is easier, and the compiler can help catch errors, too. What's not to like? Of course, C# has structs which makes ...


1

F# solves this problem nicely with measures: [<Measure>] type cm [<Measure>] type ml = cm^3 For other languages, its a tradeoff (like everything). Encapsulating primitives may have an impact on performance and space, but has benefits in type safety. You may confuse younger developers (and possibly older ones too), so there are potential ...


2

It depends on the language as well as how much effort you are willing to invest for increased correctness. There is a delicate balance between "concise code" and "rigorous code", but the location of this will vary from language to language and also depending on personal taste and circumstances. For example, if you're just prototyping, it may not be ...


0

You could probably figure this out by checking over the use cases of a quick sample. I'd say this makes sense if you can easily summarize and implement each of the use cases of, say, a numerical type. The entire point of a type system is to help you realize when you're working with the wrong type, and that can catch lots of issues before they happen. It ...


3

I would say yes if that type has a meaning more than just the simple value. In your example, Speed and Mass might be represented by a double, but they have different meanings, and they have different calculations that can be done on them. I can tell you from personal experience that doing this (it's called micro domain btw), has made my code much more ...


2

Advantage: GUID is unique so in the long run if you run into this scenario where you can join using just Guid rather than PK+other field. ex:there sales, order, adjustment, and there is stock, instead of join using PK and transaction type, you can just join using Guid since it 99.9...% guaranteed unique. By using GUID you can generate GUID from code so it ...


1

Well as already stated in the comments of the other question, this is nonsense if you won't query using the id at all. If you use just the GUIDs then leave out the clustered index and just setup the no clustered index on the GUIDs. But never use the GUIDs as clustered index unless you want to have a stress test on your I/O subsystem. ;-)


2

There's nothing wrong with having distinct methods in your web service. This makes the service have a very explicit contract and it should easy to use for your clients. For example, your initial service may have: GetDeadlineOrders GetProcessedOrders If you have to add another method in the future like: GetExpiredOrders Your service is forward ...


1

No i think you're right. Of course you could also design your interface to be more flexible regarding querying. Let's just call it "design ahead". But of course this conflicts with YAGNI. So you'll need to compromise. Another alternative would be to run the old and the new service version on different ports /URLs - thus getting rid of the downtime. You'll ...


-4

A closure is a shorthand way of writing a method where it is to be used. It saves you the effort of declaring and writing a separate method. It is useful when the method will be used only once and the method definition is short. The benefits are reduced typing as there is no need to specify the name of the function, its return type or its access modifier. ...


1

Christopher did a very good job of enumarating the disadvantages of a one-project-per-repository model. I would like to disucss some of the reasons you might consider a multiple-repository approach. In many environments I have worked in, a multi-reposity approach has been a reasonable solution, but the decision of how many repositories to have, and where ...


0

It might be that git-subtree (see Atlassian blog, medium blog, or kernel link) would be a good fit for that you have. So, each of your top level project would use a set of subtree at possibly different version(s).


2

TL;DR Leakage of implementation detail due to MATLAB ".m" files being shipped in source code form. Frequent changes of software requirements, features, and implementation detail. Complexity due to many different underlying dependencies, all of which suffer from the phenomenons listed here. Every complex software system (consisting of multiple ...


0

To check the stacktrace, I incremented a static int in the update() method of all the listeners. I added a System.out.println() in the method where I call notifyListeners() and in the update() methods of the listeners to see the value of the static. Following is stacktrace values - public static int observer = 0; //Initialized StackTrace : After ...


9

Neither foolish nor crafty I believe: MATLAB software is used for very serious engineering, science, finance, and many other fields. This being the case, MathWorks (the company that develops Matlab) are very careful not to publicly document things that they are not 100% certain will remain as-is in future Matlab versions. There are numerous examples of such ...


2

C and C++ are different in this respect. C 2011 Online Standard 6.7.6.3 Function declarators (including prototypes) ... 10 The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters. ... 14 An identifier list declares only the identifiers of the parameters of the function. An empty ...


3

Maintainability trumps all. Unless you have a pressing reason not to, follow the conventions as they appear in the reference material. In this case, the first Google hit is the documentation for validations at rubyonrails.org, which shows a strong preference to the validates form. The only counter example I could find was validates_associated, which makes ...


2

In general, notifyListeners is implemented as a list of delegates/observers which are just plain old functions that get called in order. So the observer functions will generally be invoked during the notifyListeners call (like your comment implies). There are different possible implementations, some that run in parallel in background threads, some that ...


15

First of all, there is nothing that is impossible without using closures. You can always replace a closure by an object implementing a specific interface. It's only a matter of brevity and reduced coupling. Second, keep in mind that closures are often used inappropriately, where a simple function reference or other construct would be more clear. You ...


2

In the Implementation of notifyListeners();//This invokes onUpdate() in "implements Observer" is normally a loop over all registered Observers. In this loop is normally a direct call to onUpdate() on each registered Observer. Be sure not to block the execution in the implementation of onUpdate()


5

There is a common and dangerous myth that types like uint32_t save programmers from having to worry about the size of int. While it would be helpful if the Standards Committee were to define a means of declaring integers with machine-independent semantics, unsigned types like uint32_t have semantics which are too loose to allow code to be written in a ...


2

You have a mentor! Wow, great first step. At least somebody cares. The thing about writing code is that any idiot can do it. And a lot of idiots do. The difference between idiot code, and good, clean, maintainable, documented code that works well and is easy to maintain... a bit like the difference between chalk and cheese. Things like coding standards, ...


1

Is my mentor's concern for code quality excessive? Possibly. Your statement that only one (his) version of solving a problem hints to it. But then he probably is way more competent than you are right now, so it might just a (wrong) impression that you get. Others have pointed out how what he does sounds perfectly reasonably. But it shouldn't really ...


2

Your mentor is taking his role seriously; you should always appreciate that. By holding you to a high standard, he is helping you develop the practices and proficiencies that will serve you well in your career. By pointing out errors made by others, he is helping you better recognize bad code so that yours will more often be better. To become expert at ...


-8

This is an opinion question so I'll give my opinion as a desktop and web programmer. Yes his concern are excessive in the context of web development in JavaScript. Such concerns apply to large codebase written in strong typed languages that have to be maintained for decades. JavaScript was never meant to follow best practice and industry standards. It was ...


6

for the first time feeling like I get close to being competent. I've been programming for over twenty years, and every year I wind up saying that to myself at least once or twice. anything takes a whole lot of time because I have to find the best way to do it or else its a waste of time, it also feels like my creativity doesnt matter because there ...


1

First, reconsider how you are defining module boundaries. "Compile-time settings" is a perfectly reasonable module. If it feels cleaner to split a responsibility off, it should be split off. As Basile pointed out, GNU autoconf is extremely common for this purpose. It generates one header file you can include elsewhere as needed. Just take care to make ...


4

Placing all of the compile time switches into 1 central file makes finding and changing them easy. That said, compile time switches can be confusing, particularly if there is a significant quantity of them. I worked on an embedded project where there were a few different boards to control different hardware, but had the same MCU, communication protocols, ...


6

"Done is better than perfect" I hate to break it to you, but code can always be made better, code is never perfect. If you think your code is perfect, you probably haven't looked at it enough yet, or you're no real engineer, as a real engineer can always make things better than they are. (Or, in the programmers lingo, a real hacker can always make things ...


0

(I suggest to cross-compile on a Linux running on your laptop; it has lots of good tools helpful for cross-development) The compile time parameters are probably best to be put in some header file with #define, but that header file could be generated (at build time) by some configuration script. (look perhaps into GNU autoconf for inspiration, but is is ...


21

To tell you a little about myself, I'm a newbie programmer working internships and learning a lot from experienced programmers [...] This sentence it seems to me is the key to the answer. I manage teams of programmers. When I do code review with programmers in general (of good and not so good levels of skill) I will get them to write code to meet or ...


9

Your mentor may be an excellent coder, but... Does he have the authority to review and change all the code? Is he potentially imposing stylistic changes on functional code rather than fixing bugs/preventing dangerous behavior? Are the changes being made backed up by unit tests and/or functional tests? Was there significant unit test coverage before the ...


1

When I mentor I always need to keep in mind that my pov is not the absolute truth. Design is still a creative process, but the more I learn the more I put constraints on my creativity, which I don't think kills creativity, it actually makes it stronger. Some of my ideas are still experiments and I can't enforce those to newcomers. Leaving aside "the ...


8

There are two issues here: The issue of your mentor disliking your solution is hard to qualify without concise examples. Maybe if you posted your code, you would find that everybody agrees with your mentor and that you are using the wrong approach (do not worry about it, the fact that mentors exist is the prove that most people need to get some actual ...


128

"Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live." (Took it from here) That said: there is no level of »excessive« for code reviews. I'm a newbie programmer working internships and learning a lot from experienced programmers What is more important than writing code is reading code ; read ...



Top 50 recent answers are included