4 ms·
We don't talk in maximally compressed strings; a bit of redundancy in grammar helps make sure people can understand each other. The fact that spellcheckers are
by lmm 4y ago
We don't talk in maximally compressed strings; a bit of redundancy in grammar helps make sure people can understand each other. The fact that spellcheckers are possible doesn't mean our language is too sparse and wasteful.
A lot of programming languages have a lot of room for improvement though.
- WalterBright 4y agoA programming language with no redundancy in it means the compiler cannot detect any errors - because every sequence of characters forms a valid program. The skill is in selecting the optimal amount and form of redundancy. For example, the typical ; statement terminator is redundant. People often ask, since it is redundant, why not remove it? People have tried that, and found out that the redundancy makes for far better error detection.
- lmm 4y agoOn that specific example, not my experience at all. (The general point is of course valid, though I think it follows very directly from what I said)
- pharmakom 4y agoSemicolon is a strange example when so many successful languages don’t have them. I think a better example is CoffeeScript, where almost any string is a valid program but probably not the one you wanted.
- WalterBright 4y ago> Semicolon is a strange example when so many successful languages don’t have them. They usually have another statement terminator instead, like a newline.
- amelius 4y agoNo, with redundancy your compiler can catch a certain class of errors (call them "avoidable") that doesn't exist in case of no redundancy. Of course, in both cases you still have the unavoidable errors.
- ColonelPhantom 4y agoI think the problem is not that "not all tokens are valid" Rather it is that we often repeat the same token sequences, and we should seek to abstract those predictable sequences into more unique tokens, e.g. by turning it into a library function. Of course, the downside is that now you have way more tokens you need to know to understand some code, similarly to how Haskell code tends to have tons of mega-abstract function combinators or whatever whereas Go code is very simple. Which one is more readable depends on the reader, because a language like Go requires the reader to sift through more details, whereas Haskell is much terser but also requires much more pre-existing knowledge to understand. I'm wondering if we can use these code-generation models to find "low entropy code" that is a prime target for turning into libraries.
- newaccount74 4y agoI think the Dont-Repeat-Yourself mantra is a bit overused. For example, assume you have a bunch of functions that all have the following code sequence A() B() C() So someone thinks, hey, lets extract that bit, and create a function that does all three things def ABC(): A() B() C() Now the calls site is much simpler and there is no more repetition: ABC() Except you realise that in some call sites the B() call was missing, so to fix that you add an argument: def ABC(doB): A() if(doB): B() C() The call site now looks a bit less clean, but still no repetition! ABC(True) or ABC(False) Then you realise in some cases the C() call is not necessary, so just add another argument: def ABC(doB, doC): A() if (doB): B() if (doC): C() And your call sites look like this: ABC(True, False) etc. At that point the repetition in the original is definitely preferrable...
- lmm 4y agoA codebase is a living thing. Inlining a function or splitting it into multiple cases should always be an option, and boolean flags are generally a code smell. I don't see this as an argument against DRY; when the facts change, your code structure needs to change too, but that doesn't mean your original structure was wrong.
- 4y ago