3 ms·
Redundancy is an argument against braces, not in favor. 'They're like guard rails on the highway, they make totally explicit what is going on.' Using this log
by nailer 17y ago
Redundancy is an argument against braces, not in favor.
'They're like guard rails on the highway, they make totally explicit what is going on.'
Using this logic, perhaps you should add some ASCII art to your source to denote blocks a third time? This is also a common practice. Do you feel the same about duck typing?
'The 'but you're writing for other humans to read' argument imho is not 100% the truth, you're writing for both the computer and other humans to read.'
Yes, that's true the computer also parses the code. You still haven't provided an argument why using seperate blocking formats is required.
'they cost next to nothing and make me feel a lot more like things are spelled out to mean exactly what I'm reading.'
The cost is evident: there are many cases of indentation not matching braces and vice versa, and the inconsistency between these causing confusion between the language and the humans trying to debug issues.
Tell me you've never looked for an unmatched brace in code you can otherwise parse?
- pohl 17y agoRedundancy is an argument against braces, not in favor. I disagree. I know that the word "redundant" sometimes carries a negative connotation, but the truth is that it is a mere property whose value depends upon the context and associated tradeoffs. Spacecraft have redundant systems, but those systems are far from superfluous. Human languages have built in redundancies. Generally they are there for ensuring communication still happens in a noisy environment. My music CDs have redundancy in the encoding, and thankfully at that: after years of accumulating scratches I could still rip them without loss of quality. Redundancy was a positive here too. Redundancy is a tradeoff, not an automatic downside.
- nailer 17y agoAgreed about context, but let's be clear: spacecraft and music CDs have redundancy to prevent loss. What loss are you preventing by requiring blocks be delimited twice? Have you considered that inconsistencies due to repetition are frequently themselves cites as a cause of data loss? Ever had code that looks good to you but doesn't parse because a machine is expecting an extra bracket?
- pohl 17y agoI'm no rocket scientist, but I'm pretty sure that not all redundancy in spacecraft is aimed at preventing data loss. If you look closer you'll see redundant gyros for attitude control, redundant sources of power (solar panels, fuel cells) and probably numerous redundancies in environmental subsystems on the ISS (air, water, waste), and even redundant explosive bolts for stage separation. I think jacquesm already mentioned the value of the redundancy above: you will never have a situation where a change in indentation leaves you with a runnable, but semantically-different program when you pasted code from a forum or from a machine with different tab settings. Note how the missing-bracket case in your last question is superior to this: a missing bracket offers fail-fast detection of the problem. If you indent a line wrong your program may still run, but differently: indent the last line of a block at the wrong level and it may happen after a loop rather than inside a loop. The indentation is for the person. The braces are for the compiler. I like this, personally. I understand how some may prefer the python way (it has a superficial elegance, after all). But I personally don't like the downsides that jacquesm mentioned.
- nailer 17y ago'you will never have a situation where a change in indentation leaves you with a runnable, but semantically-different program when you pasted code from a forum or from a machine with different tab settings.' In that situation, with any computer language, you'll have an unreadable program. In Python, you'll need to fix the readability before the program will execute - which is a win to me.
- pohl 17y agoI'll admit I don't know what magic the Python interpreter is capable of. I was imagining cases where an indentation change does not break readability: for foo in bar: foo.fizzle() baz.wibble() ...versus... for foo in bar: foo.fizzle() baz.wibble() ...how would it know that I wanted to wibble the baz every time I fizzle a foo, as opposed to wibbling the baz only after all foo have been fizzled?
- jacquesm 17y agoI was going to answer you until I got to the 'ascii art bit', clearly you are not taking this serious. I apologize for wasting your time with my attempt at putting in to words what I was thinking, at your request no less.
- nailer 17y agoI am taking it seriously, else I wouldn't have bothered replying to a blank 'i disagree' post with a polite request that you contribute to the discussion. The question is quite genuine - where in your view does the need for redundancy stop?
- jacquesm 17y agoBraces have a very practical level of redundancy, they cost literally next to nothing in terms of effort and reduce a whole class of errors to 'impossible'. Let me give you a simple example, in two psuedo languages, one with and one without braces: if a > b a = a + 5 b = b / 2 if (a > 0) { a = a + 5 b = b / 2 } vs if a > b a = a + 5 b = b / 2 or if (a > b) { a = a + 5 b = b / 2 } Even though the text is similarly corrupted (for whatever reason) the redundancy in the second example makes it clear that something is amiss, you could even lose the second brace and still at least know that all is not kosher in that segment. That's not 'ascii art', that's functional. Redundancy definitely has it's uses. I'm going to do some digging later on and find a bunch of examples of broken code due to cut & paste problems, some of it on the django site, no less. That's something that would never happen in C or any other 'overspecified' language. And regarding 'finding that matching bracket' that is exactly what they're for, if you can't match the bracket chances are that you really do have a problem in the code.
- nailer 17y agoIf you've spent any time with Python, it should be immediately clear that: if a > b a = a + 5 b = b / 2 is quite different from: if a > b a = a + 5 b = b / 2 Without needing a second markup for the compiler to emphasize the point.