(autodidact developer here, feel free to ELI5 and enlighten me)
(autodidact developer here, feel free to ELI5 and enlighten me)
x = some_long_expression
+ another_long_expression
problem? In Python you need to be careful to wrap that in () or use a \ before the newline to avoid it parsing as two lines, e.g. x = some_long_expression;
+ another_long_expression;
In particular, if you have a builder expressions let x = someBuilder()
.setVal(x)
.build()
You'd need to wrap the entire thing in () to avoid it getting mad, right?So if you're going to terminate expressions with ), and start them with (, why not just terminate them with ; instead?
Javascript is a "Semicolons Optional" language, but it's actually the worst of both worlds, as you have to be very careful not to wrap lines like
function() {
some stuff;
return
really_long_named_thing;
}
As it'll just insert a ; on the return, returning undefined for you.I guess that's because in the REPL Python need's to know whether the line has finished yet or not. OCaml and F# uses two semicolons ';;' for that purpose, but only in the REPL. In Haskell you can use braces and semicolons or '{:' and ':}' in the REPL.
salary = 100500
newsalary = (salary * 0.02
+ salary)
newsalary will the same as salary. There are no diagnostics.Yes, you can fix it by moving the + up a line but this should be a purely style thing, not semantics.
For example, to do method chaining across multiple lines, Python requires parentheses around the whole chain. That's a quirk of being a whitespace-dependent language.
In general, I think people who advocate for braces and semicolons just find it easier to reason about the code when they know that the formatting doesn't matter. All the flow is done via visible glyphs.
Edit: I meant to add: you need to decide whether ";" is terminates or joins statements if you have statements in the language.
The downside of assuming statements end at the end of the line is that you need to have special rules for when that isn't the case (such as Python's implicit statement continuation inside braces), while always having a terminator is simpler and more consistent (all statements end with a semicolon) at the cost of extra characters.
Just didn't got what you mean by "python's implicit statement continuation inside braces" ?
x = (
object
.method1()
.method2()
)I'm always flabbergasted at this argument.
I'll run auto tools during check-in, but not during coding sessions.
My point being that where you draw the line between what you consider automated vs not is pretty arbitrary.
Unless you are doing this for performance reasons, this one I'll never understand.
I'd much rather type "x.someP" and hit tab then type in "x.somePropertyThatHasARidiculousNameIAlwaysForget" after having to consult the documentation yet again to get the name.
If I can't recall "x.somePropertyThatHasARidiculousNameIAlwaysForget" then there are other more serious problems.
I just prefer to press less keys. It shouldn't obscure anything in a decent IDE.
Often you are working with other people's code and having to "recall" every single property, method, etc declared is not practical, hence why I mentioned having to keep referring to the documentation for things you are not accessing very often.
If I keep forgetting that a property is .lastname and not .lastName in a library I'm using I can just type "last" and press tab.
This is even more crucial in dynamic languages like JS, where you will get a failure at runtime and not compile time.
It doesn't make you any "less of a programmer", it makes you a more efficient one once you are used to it.
Autocomplete in code seems to mostly be papering over design smells that should be fixed.
I have no control over third-party dependencies and how they name things.
That is just another layer of abstraction which leads to even more confusion.
These abstractions can be taken to the extreme in things like Java, that's how you end up with a class named "InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState".
If you wrap that in a new interface "IFIFTPIFTPMBWNFS" or even "crazyFrameStuff" (ridiculous enough), now you have to figure out what that actually is while debugging.
If one just comes to terms with the fact that Intellisense (and showing the method signatures while implementing) is extremely helpful even to very senior developers, life can be much easier.
It's not cheating.
You're free to find Intellisense etc. useful. I just don't. I go to great lengths to have an uncluttered view of the code when I work, because I find it far more preferable to focus on just the code. I'm not against it in principle - I've just not seen any solutions like that which works for me. I don't tend to need to look up methods much; when I work on a piece of code I tend to hold the APIs in memory pretty effortlessly, so that's just not much of a consideration.
I spent years actually looking at implementing visual languages because I liked the idea of providing more contextual information and views of information flows etc. to aid development, but I've yet to find something that works better for me than an uncluttered view of the text.
let x = if y { a } else { b }Meanwhile Rust avoids any kind of behaviour that isn't clearly visible in the code. That includes unambiguous syntax, like the mandatory curly braces for loops and conditions. And of course the semicolon as a clear separator, which comes in handy when iterators or the builder pattern are used.
Really, Rust only doesn't look like OCaml because less people would use it if it wouldn't have braces and semicolons.
Found this post, for example: https://news.ycombinator.com/item?id=5607912
I wouldn't mind Python's whitespace indents in Rust though!
Of course you could, because a semicolon-less return doesn't work in the middle of a statement.
You can't do
bla;
a
bla bla;
b
instead of bla;
return a;
bla bla;
b
Yes, the code after the `return` isn't reachable and the Rust compiler doesn't like that ;) {123 456} + {789}
was 1245 instead of 124_245.