I knew someone in university who refused to use any C++ loop type other than do/while. They wrote some pretty crazy code, and it wasn't efficient or really very readable, and things that should have been an easy for loop turned into awkward as fuck do/while conditions and loop variables. But, it worked...
We didn't get graded on style, so they did fine. But working with them on group projects was... special.
It seems to be web scraping, and code like that is often the cleanest or even the only way do to things. There are rarely booleans hanging around in HTML.
I take it you're joking, but it should be pointed out (due to the other comments) that this is not normal, for anyone not familiar with the language.
Python tends towards "asking for forgiveness", so you wouldn't check for example if a string is parseable before calling int on it. You'd simply call int on it, and handle the failure if it wasn't parseable.
That's doesn't mean however that it makes sense to use an assert with a try in a case like this. This is "asking for permission", but with a try, which is an abuse of try. There's no reason to not use a conditional statement/expression here.
I completely agree with you! Except for the performance part, python exception are handled differently than others languages and that's why there a kind of abuse, even in the language design itself. You don't have any performance drawback by throwing and catching exceptions.
( I can't find sources right now but I think it's pretty easy to find)
197
u/_PM_ME_PANGOLINS_ Aug 27 '21 edited Aug 27 '21
No ifs
23
u/MattiDragon Aug 27 '21
Is this javagony but python???
12
u/MkemCZ Aug 27 '21
Who needs
ifs anyway?8
u/make_me_a_good_girl Aug 27 '21
I knew someone in university who refused to use any C++ loop type other than do/while. They wrote some pretty crazy code, and it wasn't efficient or really very readable, and things that should have been an easy for loop turned into awkward as fuck do/while conditions and loop variables. But, it worked...
We didn't get graded on style, so they did fine. But working with them on group projects was... special.
14
u/Brain-InAJar Aug 27 '21
Nobody seems to mind the fact they are trying to figure out if the user is logged in based on a hard-coded English sentence. Cool cool cool
8
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 27 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
3
u/[deleted] Aug 27 '21
Use
python -Oand you'll always be logged in2
u/CyborgTriceratops Aug 27 '21
I went the opposite way with my first text based adventure. My main room/turn in room had something like 12 nested if/thens.
2
u/Tc14Hd Aug 27 '21
the virgin if vs the try-assert chad
1
u/Voltra_Neo Aug 31 '21
How do you... Nevermind I don't even wanna know
1
u/BarryFruitman Sep 02 '21
switchwould be better :-P0
u/[deleted] Aug 27 '21
[deleted] — view deleted comment