When to make constructor explicit in C++ [closed]

The traditional wisdom is that constructors taking one parameter (explicitly or effectively through the use of default parameters) should be marked explicit, unless they do define a conversion (std::string being convertible from const char* being one example of the latter). You’ve figured out the reasons yourself, in that implicit conversions can indeed make life harder … Read more

Is this code defensive programming, or bad practice? [closed]

It looks like your colleague is misunderstanding “defensive programming” and/or exceptions. Defensive Programming Defensive programming is about protecting against certain kinds of errors. In this case x.parent == null is an error because your method needs to use x.parent.SomeField. And if parent were null, then the value of SomeField would clearly be invalid. Any calculation … Read more

How defensively should I program? [closed]

Manually checking for a configuration and throwing an exception is no better than just letting the framework throw the exception if the configuration is missing. You are just duplicating precondition checks which happens inside the framework methods anyway, and it makes you code verbose with no benefit. (Actually you might be removing information by throwing … Read more

C++ always use explicit constructor [closed]

The traditional wisdom is that constructors taking one parameter (explicitly or effectively through the use of default parameters) should be marked explicit, unless they do define a conversion (std::string being convertible from const char* being one example of the latter). You’ve figured out the reasons yourself, in that implicit conversions can indeed make life harder … Read more

Is it possible that Java String.split can return a null String[]

It never returns null. You should always check the javadoc of the method if you are not sure. For example String#split(String) says This method works as if by invoking the two-argument split method …and String#split(String,int) says: If the expression does not match any part of the input then the resulting array has just one element, … Read more

Erlang’s let-it-crash philosophy – applicable elsewhere?

It’s applicable everywhere. Whether or not you write your software in a “let it crash” pattern, it will crash anyway, e.g., when hardware fails. “Let it crash” applies anywhere where you need to withstand reality. Quoth James Hamilton: If a hardware failure requires any immediate administrative action, the service simply won’t scale cost-effectively and reliably. … Read more