Since
if(condition){ instruction; }
instead of if(condition) instruction;
is already considered good practice, couldn't it also be enforced via compiler pragma?Since
if(condition){ instruction; }
instead of if(condition) instruction;
is already considered good practice, couldn't it also be enforced via compiler pragma?In fairness, I have hit the "goto" style of bug he talks about in switch commands, when I forgot to add a break statement. But I can't remember a single time in my programming career when I added a line to an if/for/while and broke something.
I think people are wasting their energies on subjective topics like telling people to use spaces instead of tabs, or putting { on the same line as the flow control statement, or even telling people how much whitespace to use between () and where.
What we really need is a standardized formatter for any language that works like Google's Go Format. Programmers should not be spending time refactoring code just for looks. If anyone knows of a utility that does this and is easily configurable for personal taste, I would sure appreciate it. Being able to convert /* */ comments to // and back again would be a plus.
[1] http://clang.llvm.org/docs/ClangFormat.html
[2] http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclips...
[3] https://www.jetbrains.com/idea/webhelp/reformatting-source-c...
[4] https://pypi.python.org/pypi/PythonTidy/1.22
I'm confused. It sounds like you're saying
if (condition) { stuff(); other_stuff(); }
is the same as if (condition) stuff(); other_stuff();
because the brackets don't change the functionality, but they do. I might be misreading what you're saying though.The thing inside brackets in an if statement is a list of instructions, not a set, so there's no real reason that brackets use in mathematical set notation makes them natural for this use.
No, its not, since an element can be repeated in a list but not in a set. To represent a list of instructions as a set it needs to be something like a set of (position, instruction) pairs -- like lines of code in old-style BASIC, with mandatory line numbers.
> If you want to be pedantic, the instructions inside the brackets ultimately get converted to opcodes and their numeric arguments, which do form a set.
No, they still don't. The "opcodes and arguments" are just instructions in a different language, and are still a list; you can have the same combination of opcode and arguments more than once, and the order still matters.
(If you include the offset in memory at which each instruction will be loaded along with the opcode and arguments making it up, then you'd have position-instruction pairs, and you could represent it as a set. But that's not what you are writing, and the fact that there is an equivalent set representation for something you are writing as a list doesn't make set delimiters natural delimiters for the thing written as a list.)
What's the point of having branching construct that uses different syntax for exactly one instruction than for many instructions?
And if you are crazy like that then why not have:
if(condition);
that does nothing? Oh. Wait. We have that in C, Java (not C# though). I guess consistency is not the be all and end all of language design.Doesn't that depend on what you consider your condition? createSomething=function that creates something and returns true if correctly created and false otherwise
if(createSomething());
did that do nothing?
edit: perhaps nothing useful since we can't know the state returned by createSomething.
Then you consider that sets are unordered, and then the analogy doesn't make any sense any longer since the order matters for instructions.
Personally I think brackets are so important in C-like languages because they're such a pain for me to write on my keyboard.