Ultra rapid learning of Python
-
@accalia said in Ultra rapid learning of Python:
indeed, but you can't read the first and think the code is the second.
and if you can maybe a trip to the optometrists is in order?
With braces:
if (condition) { doSomething() }
That can't be wrongly parsed by a human or a compiler/interpreter
-
@timebandit said in Ultra rapid learning of Python:
@masonwheeler said in Ultra rapid learning of Python:
It's not possible to forget the indentation in Python; that will cause a parse error.
???
if (condition): doSomething() doSomethingElse()
What I really wanted was
if (condition): doSomething() doSomethingElse()
Totally different outcome, and no parser error
But it looks obviously wrong. Whereas with stuff like
goto fail
it looks right but turns out to be wrong.
-
@masonwheeler said in Ultra rapid learning of Python:
But it looks obviously wrong
How ?
Unless you know it was supposed to be like the second example.
-
@boomzilla said in Ultra rapid learning of Python:
But I also can't read the first and know that it was supposed to be the second.
As long as we're getting that deep into what-if-land, you really can't read anything and know it was supposed to be something else. If we're using braces, how do we know they put the brace on the right line and it wasn't supposed to also encompass the next line down?
-
@masonwheeler said in Ultra rapid learning of Python:
how do we know they put the brace on the right line and it wasn't supposed to also encompass the next line down?
-
@timebandit Just sayin'. "What if it's supposed to" can become a massive rabbit hole if you follow it to its logical conclusion. But if you take away the braces, that's one less thing that can go wrong. The Python style helps to make wrong code look wrong.
-
@masonwheeler said in Ultra rapid learning of Python:
But if you take away the braces, that's one less thing that can go wrong.
If you take away all the code, nothing can go wrong.
And it runs really fast too
-
@timebandit Braces aren't code; they're scaffolding.
-
@masonwheeler said in Ultra rapid learning of Python:
@timebandit said in Ultra rapid learning of Python:
@masonwheeler said in Ultra rapid learning of Python:
It's not possible to forget the indentation in Python; that will cause a parse error.
???
if (condition): doSomething() doSomethingElse()
What I really wanted was
if (condition): doSomething() doSomethingElse()
Totally different outcome, and no parser error
But it looks obviously wrong. Whereas with stuff like
goto fail
it looks right but turns out to be wrong.It doesn't look anything like obviously wrong. What are you talking about?
-
@boomzilla It does if you're the one who wrote it and you know those two lines are supposed to be executed together.
-
@masonwheeler said in Ultra rapid learning of Python:
@boomzilla said in Ultra rapid learning of Python:
But I also can't read the first and know that it was supposed to be the second.
As long as we're getting that deep into what-if-land, you really can't read anything and know it was supposed to be something else. If we're using braces, how do we know they put the brace on the right line and it wasn't supposed to also encompass the next line down?
I'll drop that line of argument if you'll drop all the other defenses of python formatting not being problematic.
-
@masonwheeler said in Ultra rapid learning of Python:
@boomzilla It does if you're the one who wrote it and you know those two lines are supposed to be executed together.
That's bullshit. Maybe I wrote the code 10 years ago (or 10 minutes ago). Maybe I don't code on things where I'm the only contributor.
-
@timebandit said in Ultra rapid learning of Python:
@accalia said in Ultra rapid learning of Python:
also it does have the lovely side effect that you can't get bugs like this:
if (someErrorCondition)
doAThing();
return false; // We failed
return true; // We succeededin C like languages that snippit always returns false, which is a bug!
Always put braces, even if they enclose only one line
Never!
-
@boomzilla said in Ultra rapid learning of Python:
I'll drop that line of argument if you'll drop all the other defenses of python formatting not being problematic.
The only actual example of it being problematic I've seen that isn't a wild and bizarre "what-if" is about pasting code blocks in. And that's really only problematic if you're a complete n00b who doesn't automatically adjust the indentation the second he pastes it. Because really, anyone with a month's experience with Python would do that, if necessary, without a second thought.
@boomzilla said in Ultra rapid learning of Python:
That's bullshit. Maybe I wrote the code 10 years ago
Then why didn't you notice it 10 years ago?
(or 10 minutes ago).
If your attention span is honestly that short, what are you doing in this field where it's crucial to be able to juggle a half-dozen interrelated pieces of data in your head at any given moment?
Maybe I don't code on things where I'm the only contributor.
Then why didn't the person who did write it notice?
-
@kt_ said in Ultra rapid learning of Python:
@timebandit said in Ultra rapid learning of Python:
@accalia said in Ultra rapid learning of Python:
also it does have the lovely side effect that you can't get bugs like this:
if (someErrorCondition)
doAThing();
return false; // We failed
return true; // We succeededin C like languages that snippit always returns false, which is a bug!
Always put braces, even if they enclose only one line
Never!
THE NESCAFÉ RATION HAS BEEN REDUCED BY 30 MILLILITERS
-
@masonwheeler said in Ultra rapid learning of Python:
Then why didn't you notice it 10 years ago?
Y'know, sometimes you sound like someone who has worked with a lot of code. And then you say something like this and I wonder if you even know how to spell pythong.
-
@boomzilla said in Ultra rapid learning of Python:
I wonder if you even know how to spell pythong.
Was that deliberate?
-
This post is deleted!
-
@masonwheeler said in Ultra rapid learning of Python:
@boomzilla said in Ultra rapid learning of Python:
I wonder if you even know how to spell pythong.
Was that deliberate?
See the lawn? Stay off of it.
-
Seems to be a lot of classic arguments cropping up lately. Braces vs. indentation here, exceptions vs. error returns over in Enlightened. Could a static vs. dynamic typing argument be in the works?
-
@mzh No, too much value. How about spaces vs tabs?
-
@boomzilla said in Ultra rapid learning of Python:
@kt_ said in Ultra rapid learning of Python:
@timebandit said in Ultra rapid learning of Python:
@accalia said in Ultra rapid learning of Python:
also it does have the lovely side effect that you can't get bugs like this:
if (someErrorCondition)
doAThing();
return false; // We failed
return true; // We succeededin C like languages that snippit always returns false, which is a bug!
Always put braces, even if they enclose only one line
Never!
THE NESCAFÉ RATION HAS BEEN REDUCED BY 30 MILLILITERS
Seriously, though. Every time this topic comes up, you say that braces should be there, even around one-liners. I (almost) never do that. If a line is long, or if I need to split it, then I usually put it on it’s own line, inside the braces. I have this rule that if I omit the braces, then I want there to be max one line below the if statement. But that’s it.
-
@kt_ I've said before that I can make an occasional exception for something really trivial:
if( foo ) bar();
There are always exceptions.
-
@boomzilla said in Ultra rapid learning of Python:
@kt_ I've said before that I can make an occasional exception for something really trivial:
if( foo ) bar();
There are always exceptions.
Yes, they are. And nulls, too. Which lead to even more exceptions. NullReferenceExceptions.
-
@kt_ said in Ultra rapid learning of Python:
@boomzilla said in Ultra rapid learning of Python:
@kt_ I've said before that I can make an occasional exception for something really trivial:
if( foo ) bar();
There are always exceptions.
Yes, they are. And nulls, too. Which lead to even more exceptions. Null
ReferencePointerExceptions.
-
@mzh said in Ultra rapid learning of Python:
Seems to be a lot of classic arguments cropping up lately. Braces vs. indentation here, exceptions vs. error returns over in Enlightened. Could a static vs. dynamic typing argument be in the works?
Nah. Python's use of dynamic typing is one of the things I don't like about it. :P
-
@kt_ said in Ultra rapid learning of Python:
I (almost) never do that.
I eat at McDonalds. I recognize McDonalds is bad for me.
The question isn't whether you do it or not-- everybody does stupid shit sometimes-- the question is whether you think it's good code or not.
And if you think it's good code to leave-off optional braces, you're wrong. That's all there is to it.
-
@blakeyrat said in Ultra rapid learning of Python:
@kt_ said in Ultra rapid learning of Python:
I (almost) never do that.
I eat at McDonalds. I recognize McDonalds is bad for me.
The question isn't whether you do it or not-- everybody does stupid shit sometimes-- the question is whether you think it's good code or not.
And if you think it's good code to leave-off optional braces, you're wrong. That's all there is to it.
No, your rong.
-
@pleegwat said in Ultra rapid learning of Python:
Or make the braces mandatory on a language level - I'm sure plenty of C-like languages have done that, though I couldn't name any for certain. I'm thinking Java though?
Rust does.
-
@kt_ said in Ultra rapid learning of Python:
@blakeyrat said in Ultra rapid learning of Python:
@kt_ said in Ultra rapid learning of Python:
I (almost) never do that.
I eat at McDonalds. I recognize McDonalds is bad for me.
The question isn't whether you do it or not-- everybody does stupid shit sometimes-- the question is whether you think it's good code or not.
And if you think it's good code to leave-off optional braces, you're wrong. That's all there is to it.
No, your rong.
I don't know what the Lepcha have to do with this.
-
@pleegwat said in Ultra rapid learning of Python:
Or make the braces mandatory on a language level - I'm sure plenty of C-like languages have done that, though I couldn't name any for certain. I'm thinking Java though?
Java goes better. It makes provably dead code illegal.
-
@mzh said in Ultra rapid learning of Python:
Seems to be a lot of classic arguments cropping up lately. Braces vs. indentation here, exceptions vs. error returns over in Enlightened. Could a static vs. dynamic typing argument be in the works?
No, but it is time for a vim vs emacs war.
Emacs is obviously superior.
-
-
@pleegwat said in Ultra rapid learning of Python:
@accalia said in Ultra rapid learning of Python:
@timebandit said in Ultra rapid learning of Python:
@accalia said in Ultra rapid learning of Python:
also it does have the lovely side effect that you can't get bugs like this:
if (someErrorCondition)
doAThing();
return false; // We failed
return true; // We succeededin C like languages that snippit always returns false, which is a bug!
Always put braces, even if they enclose only one line
see. the point is that particular error is impossible in python.
only lint tools can show you the error (and then only maybe and only if you use them) in C like languages.
:-D
Or make the braces mandatory on a language level - I'm sure plenty of C-like languages have done that, though I couldn't name any for certain. I'm thinking Java though?
Java doesn't, but Go does.
-
@pleegwat said in Ultra rapid learning of Python:
Or make the braces mandatory on a language level - I'm sure plenty of C-like languages have done that, though I couldn't name any for certain. I'm thinking Java though?
The newest generation—Go and Rust—do (they make the parenthesis optional instead), but I didn't find any in the previous generation (Java, C# and their derivatives like Scala or Kotlin etc.) that would.
@hardwaregeek said in Ultra rapid learning of Python:
Perl does, but Perl has other ... issues.
Well, no, Perl does not, but if there are no braces, it looks for the statement before the if for extra fun.
By the way, Python partially replicated it with it's if expression of the form “expression-if-true
if
conditionelse
expression-if-false”.
-
@cartman82 said in Ultra rapid learning of Python:
Anything that add more "texture" to code
I like your choice of words. That and I absolutely agree with you on the concept.
-
@dkf said in Ultra rapid learning of Python:
No, but it is time for a vim vs emacs war.
Emacs is obviously superior.
-
@ben_lubar said in Ultra rapid learning of Python:
@accalia SYNTAX ERROR
The Go Playground
NOT SYNTAX ERROR
The Go Playground
ALSO NOT SYNTAX ERROR
The Go Playground
FTFY:
SYNTAX ERROR
package main func foo() bool { if (someErrorCondition) doAThing(); return false; // We failed return true; // We succeeded } var someErrorCondition = false func doAThing() {} func main() { foo() }
NOT SYNTAX ERROR
package main func foo() bool { if someErrorCondition { doAThing() return false // We failed } return true // We succeeded } var someErrorCondition = false func doAThing() {} func main() { foo() }
ALSO NOT SYNTAX ERROR
package main func foo() bool { if someErrorCondition { doAThing() } return false // We failed return true // We succeeded } var someErrorCondition = false func doAThing() {} func main() { foo() }
-
@bulb said in Ultra rapid learning of Python:
The newest generation—Go and Rust
I take offense to that statement. While released in the same decade, they definitely belong in different periods in computer science. Go is very oldschool (C with a couple improvements and GC - basically Java), while Rust is avant garde of programming languagre theory.
-
@gąska said in Ultra rapid learning of Python:
Rust is avant garde of programming languagre theory
But incapable of hosting a GUI platform
-
@jaloopa ARM was incapable of running video games for a long time, too.
-
-
@cark said in Ultra rapid learning of Python:
@boomzilla said in Ultra rapid learning of Python:
if (foo) bar();
FTFY
The goggles!
-
@gąska It's an insult to Java to compare it to Go. For one thing, Java has real exceptions. And generics (now). Go has... uh. A gopher logo?
-
@dkf said in Ultra rapid learning of Python:
Java goes better. It makes provably dead code illegal.
Go follows this basic philosophy, and takes it far further than Java. Which is great for deployment, but really gets in the way of incremental development!
-
@blakeyrat said in Ultra rapid learning of Python:
@gąska It's an insult to Java to compare it to Go. For one thing, Java has ... generics.
Sort of, for sufficiently low values of "generics."
-
Status: I botched the freestyle speaking over Skype part of the interview and they don't want me anymore. FML
-
@gąska Good practice for next time.
-
@blakeyrat "it doesn't matter how much you suck at programming, good presence is the only thing that matters"?
-
@gąska I'd go more with, "It doesn't matter how much you suck at programming as long as you can convince them to pay you for it," and the practice makes you better at the convincing. It also doesn't matter how good you are if you can't convince them.
To clarify, the skill only matters after you convince them to pay you.