Tag Info

Hot answers tagged

10

According to Greg Young, this idea originated from Bertrand Meyer: Command-Query separation. It states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, Asking a question should not change the answer.1 More formally, methods should return a value only if ...


8

This heavily depends on definition of list and tree. Mathematically list doesn't mean anything and tree is just special subset of a graph. Inferring from your question, your teacher's definition of tree is nested lists. In which case, list of nesting depth of 0 is still a tree. So abc = [1, 2, 3, 4] Is a tree. In this case, the list is subset of tree. ...


4

Since you mentioned Matlab (and IDL) vs C++ I'll address my answer to that scenario. Short summary of indicators when switching from a prototyping to production language is necessary: When programming data structures , algorithms, or distributed processing architectures not well supported by the prototyping language, or better supported by the ...


4

I assume you mean "get rid of accessors and make private members public"... well, from a design point of view, a getter/setter is not doing much more than a public variable anyway, just with more layers. Now, a good class design would not even begin to consider exposing a variable at all, it instead adds methods that apply to the internal state of the ...


3

I suspect that the C language choose the continue statement because of its association with loops from FORTRAN, and many languages (C++, Java, C#) owe some lineage to C. (And FORTRAN is pretty old but maybe as @GilbertLeBlanc notes, perhaps FORTRAN got CONTINUE from somewhere else like COBOL?) The CONTINUE statement in FORTRAN is commonly used at the end ...


3

Tomorrow your boss will tell you that they want to have most of the messages in RED color and a few in BLUE with extra padding... and you are pretty much into major refactoring with both of your approaches. Your Program class is responsible for decision making and printing at the same time. That way Single Responsibility Principle has been broken. So, I ...


3

I also believe that it's more clear to have an unique invocation if this one need to be changed later. The uniqueness of the invocation can be subject to change, too. Maybe you don't want to print anything any more if there is no argument and you don't want to call Print at all in this case. I don't think there is a definite answer to your question ...


3

I'd clearly choose the extra variable approach, because DRY. The varaible name additionally conveys the meaning of the argument (e.g. it could be warning or log_entry, etc).


2

A competent production-quality industrial-strength compiler, with optimization turned on, will automagically transform Snippet2 into Snippet1. If your compiler falls into that category (and most do), there's no real reason for a preference. Personally, being one who believes in being terse, I'd've coded it as: private static void Snippet3(string[] args) { ...


1

I think you are confusing the issue by using lambda expressions in the structure. The expression lambda:5 is neither a list nor a number. It is a function. So the data structure in your example is not a tree of numbers, since one of the leaves is a function rather than a number. But disregarding the lambda, the expression [1, 2, 3, 4] is a list, and also a ...


1

Ceylon has full support for first-class union and intersection types. You write a union type as X | Y and an intersection type as X & Y. Even better, Ceylon features a lot of sophisticated reasoning about these types, including: principal instantiations: for example, Consumer<X>&Consumer<Y> is the same type as Consumer<X|Y> if ...



Only top voted, non community-wiki answers of a minimum length are eligible