4 ms·
Walter Bright - Programming Language Ideas That Work and Don't Work [video]
- bandyaboot 3y agoImplicit variable declaration “doesn’t work”, he says. Those millions upon millions of developers creating real world value using Python sure are going to be surprised when they find out.
- kybernetikos 3y agoWell there's a reason that JavaScript used to support this but no longer does. Characterising it as 'implicit variable declaration doesn't work' seems like a fairly reasonable summary of the view of a very large number of people. To be true it doesn't need to be impossible to write code in a language with implicit declaration, it just needs to be significantly worse.
- bazoom42 3y agoIn JavaScript, implicit varible declarations goes to the global scope, which is obviously a footgun. In python they go to the local scope as you would expect.
- kybernetikos 3y agoGoing to local scope is obviously better, but it still allows misspellings (some of which are very difficult to see) to create new variables and have code that looks like it works but does something entirely different to what you expect.
- gary_0 3y agoTo be fair, most of his talk is biased towards compiled and statically typed languages (topics like compiler switches, ABI, etc). Not that compiled languages can't have implicit variables, but a lot of people would find it surprising behavior. People familiar with compiled languages expect the compiler to be strict and tend to dislike it when it guesses (especially when it guesses wrong).
- kazinator 3y agoPython doesn't have implicit declaration. The first occurrence of the assignment syntax declares the variable and binds it to a value. Proof that Python doesn't have implicit declaration: >>> foo Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'foo' is not defined Pyhon's design sin is that it fails to distinguish the binding of a variable from assignment. The programmer cannot locally (i.e. just in that statement alone) express "I expect this statement to be freshly creating a variable, introducing it into the scope, with value 42" and "I expect to be assigning value 42 to a variable which already exists in the scope (or else this should be diagnosed)". An example of a language actually without declaration is Awk. This helps one-liners be very terse, but hinders large programs. Proof that awk has implicit declaration in contrast to Python: $ awk 'BEGIN { print foo }' $ No errors. The shell has implicit declaration: $ echo $foo You turn it off in serious scripts with "set -u" to have it diagnosed.
- adrianmsmith 3y ago> Pyhon's design sin is that it fails to distinguish the binding of a variable from assignment. The programmer cannot locally (i.e. just in that statement alone) express "I expect this statement to be freshly creating a variable, introducing it into the scope, with value 42" and "I expect to be assigning value 42 to a variable which already exists in the scope (or else this should be diagnosed)". I'm not entirely sure this is a bad thing? I'm learning Go right now, and I'm encountering plenty of code like: err := DoFoo() if err != nil .... err = DoBar() if err != nil .... The problem with that is that if you remove the DoFoo line you have to change the DoBar line, even though nothing's really changed there. An (albeit small) waste of time, an extra thing to think about which has nothing to do with the problem you're solving, more lines to review in the PR, and more chance of merge conflicts later.
- hamdouni 3y agoYou can avoid this by using : if err := DoFoo(); err != nil { ... The 'err' variable will be local to the 'if' so you can write also : if err := DoBar(); err != nil { ... It is also nice to write it in one line :-)
- pjmlp 3y agoThey actually do, when they have to track down a bug caused by a typo, or have the happy task to refactor a piece of code and forget a couple of places.
- IshKebab 3y agoCome on, obviously when he's saying it "doesn't work" he doesn't mean "it makes it impossible to use the language to write software".
- IshKebab 3y agoThis is a pretty great talk. I listened to it as a podcast instead of a video and it worked very well. You can even figure out the mistakes he's talking about without the code because we've all been there, e.g. the for loop, presumably this: for (int i = 0; i < 10; ++i); { ... I agree with him on all points, though I'm not sure about warnings. I think most people are against warnings because they've been traumatised by C/C++ where a ton of the warnings really should be errors (my favourite is -Wreturn-type which can cause insanely difficult to debug issues if omitted). Any sane C++ project has to turn on `-Wall -Werror` because so many of the warnings are really "backwards compatible errors". So warnings are a disaster in C++ but I don't think that means they fundamentally are. Warnings in Rust seem to be fine. And having no warnings at all is more annoying than Rust's approach. Go won't let you have unused variables - which is an indication of mistakes - but is really annoying when you're writing incomplete code.
- JonChesterfield 3y agoWerror means as soon as someone uses a new compiler with a new warning your code stops building. Even if it's something about misleading parenthesis or brace position. It's not a good thing to have on by default in build script.
- IshKebab 3y agoYou should have it on for CI and for first party developers by default, but have it off if you distribute your source to third parties for the reason you stated. That's kind of my point. C/C++ have a really bad implementation of warnings, which leads people to think that warnings are fundamentally a bad idea, which is not something I am convinced by.
- Gibbon1 3y agoI think people should look at the output of their compiler and fix warnings before checking in code. And frankly I'd rather the build not stop on the first error. In fact it would be best if the build system tried to link even if there are errors. Might work.
- mikewarot 3y agoThank goodness I'm not the only one who things Macros are evil. I've seen his comments here quite a bit, It's good to put a face with a name. 8) As far as compiler flags, that's an interesting take on things. From the meta perspective, not making a decision but putting in a feature switch is essentially kicking a can down the road, with all the grief that eventually entails.