Tag Info

Hot answers tagged

21

In my view, the explicit else block is preferable. When I see this: if (sky.Color != Blue) { ... } else { ... } I know that I'm dealing with mutually exclusive options. I don't need to read whats inside the if blocks to be able to tell. When I see this: if (sky.Color != Blue) { ... } return false; It looks, on first glance, that it returns ...


18

The term "standards" in programming often refers to a technology/document that is governed by a group or community. The members of that group often share common invested goals, are active users of that technology and want to ensure the technology continues. There are many "things" in programming that have a community that governs them. These members can ...


15

The principle reason for removing the else block that I have found is excess indenting. The short-circuiting of else blocks enables a much flatter code structure. Many if statements are essentially guards. They're preventing the dereferencing of null pointers and other "don't do this!" errors. And they lead to a quick termination of the current function. ...


9

A standard is a technical document specifying how a technology behaves. (For some technologies, it may be some other kind of technical standard.) That's all they are and why they exist: they are documents, and they describe the technology. These documents are authored by a governing body which has the authority and trust necessary for them to be able to ...


7

Don't quit yet. Try the following first. Sell them the idea differently. Sell them the idea as "code quality". If you are the boss: Tell them that they need to improve the quality of their code. Tell them that the naming convention is the major aspect to be considered in the first phase. Tell them that code quality is going to be considered in their ...


4

I don't think you should break up the script just because of length. Any decent IDE should have the ability to collapse functions and/or skip to a specific function. There need to be good logical reason for seeing one part of it as functionally independent of the others. For example, if the function or functions for reading a file are generic enough, it ...


3

A technology standard is a specification such that two implementations of the same standard are expected to be interoperable or interchangeable. Examples: USB, Bluetooth, Java EE7, HTTP. Then there are "de facto" standards: conventions that enable interoperability, but without an explicit agreed-upon specification. Example: The Microsoft DOC format has ...


1

I usually prefix resource IDs with the "component" they belong to. Note that I say resource IDs and not View IDs because this applies to other resources too (String for example). Specifically for views, I further add the view type after the component prefix. Here's a concrete example: login_button_done (View ID) login_ok (String resource) ...


1

I think the answer is it depends. Your code sample (as you indirectly point out) is simply returning the evaluation of a condition, and is best represented as you obviously know, as a single expression. In order to determine whether adding an else condition clarifies or obscures the code, you need to determine what the IF/ELSE represents. Is it a (as in ...


1

They add visual cluttering in the code, so yes, they might add complexity. However, the opposite is also true, excessive refactoring to reduce the code length can also add complexity (not in this simple case of course). I agree with the statement that the else block states intent. But my conclusion is different, because you're adding complexity in your ...


1

One other thing to think about in this argument is the habits each approach promotes. if/else reframes a coding sample in the terms of branches. As you say, sometimes this explicitness is good. There really are two possible execution paths and we want to highlight that. In other cases, there's only one execution path and then all those exceptional ...


1

I think it depends on what kind of if statement you're using. Some if statements can be looked at as expressions, and others can only be seen as control-flow statements. Your example looks like an expression to me. In C-like languages, the ternary operator ?: is very much like an if statement, but it is an expression, and the else part can't be omitted. ...


1

The most important goal of code is to be understandable as committed (as opposed to easily refactored, which is useful but less important). A slightly more complex Python example can be used to illustrate this: def value(key): if key == FROB: return FOO elif key == NIK: return BAR [...] else: return BAZ This is ...


1

Although the if-else case described has the greater complexity, in most (but not all) practical situations it does not matter much. Years ago when I was working on software that was used for the aviation industry (it had to go through a certification process), yours was a question that came up. It turned out that there was a financial cost to that 'else' ...


1

Firstly, many answers here use the word standard. The practice of prohibiting direct queries and only allowing sprocs is not called a standard. It's a policy (see jzd's answer). Now a quick summary of what others have said here before... Pro company policy: Allows for tracking dependencies between database objects and overview how planned changes affect ...



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