Domain: entrian.com
Stories and comments across the archive that link to entrian.com.
Comments · 7
-
Re:Python is pretty decent, I only have two concer
If you're feeling *particularly* devious, you can use a little-known Python feature called "for-else" (also "while-else") which allows you to tag "else" clauses onto for loops. Such a clause executes only if the loop runs to completion 'naturally' (i.e. if no break or exception happens within the loop block).
As a relatively obscure language feature, using it might make your code harder to read. It can help make a multilevel break (chained "else: continue; break" snippets at the end of loops), and reduces the number of flag tests and sentinels you need to do (e.g. a linear search, wherein the "else" case simply contains the if-not-found logic).
There are other alternatives to multi-level break: exceptions can break out of any number of loops until they reach an appropriate handler block, and function returns can always break out of any loop up to the top of the function.
As for switch/case: In C, they were basically a thin wrapper around jump tables for most switches (e.g. enums, small integers, duff's device, etc.). Python's preferred alternatives are key-value dictionaries (hashtables) or if/elif cascades. The former is very easy to setup and manipulate in Python (e.g. {1: 'spam', 2: 'eggs', 3: 'ham'}), unlike in C or C++. The latter is far more flexible than switch/case (e.g. being able to test ranges of values with "A <= x <= B" queries, test for multiple values with "x in (A, B, C)", or do arbitrary tests like "x.isspace()"), while avoiding the complexity of an entirely new language construct.
Finally, goto exists in Python as a third-party module. Go ahead, try it: it really works!
-
Re:Why BASIC? What for?
Yeah, exacly. What bad habits? These can all be learned in python: http://entrian.com/goto/
-
Re:what I did
> Without a doubt, python should be the goto language for newb, wannabe programmers. Pssst - see what I did there.
One of the best April fools' prank I've seen; just like that April Fools' day, when Google announced the eternally expanding storage space for GMail. They're still expanding.
-
Re:Same way you get your kids interested in gaming
This was BASIC, though.
10 FOR I = 1 TO 2 STEP 0
20 PRINT "FUCK"
30 NEXT IIt's too early for me to think of a way to do it with GOSUBs, and I'm not good with coding, the problem is, when you RETURN from a GOSUB, it continues execution after the point of the GOSUB. Nested GOSUBs won't work for this (10 PRINT "FUCK" 20 GOSUB 10,) as Microsoft (at least 6502, I assume 8080 is the same way) BASIC only allows 24 nested GOSUBs, IIRC. (It DOES fill the screen on an Apple II, but it crashes out immediately after doing so, with an out of memory error.)
IIRC, the "Structured Applesoft" stuff uses GOTOs, but only sparingly, when there's no other suitable construct.
What would be more fun is this, though.
from goto import comefrom, label
comefrom .loop
print "fuck"
label .loop(Uses a fully functional goto Python script written for April Fool's that also includes comefrom.)
-
Re:BASIC is irrelevant
Surely Python is the language to start with these days? It's straightforward, doesn't force any particular model, i.e., can use for procedural, OOP, functional style.
Most importantly it's not a toy language.I've been struggling to teach programming to my kids using Python (and other languages), and have never been completely satisfied. I'm thinking that I need to start by teaching a restricted subset that looks a lot like BASIC. Two character variables are missing, but OTOH python doesn't use '$' to indicate string variables. The big thing is to include a GOTO statement, such as http://entrian.com/goto/, to be used until other flow control mechanisms are taught. I wonder if I can extend Entrian's code to include a GOSUB?
Of course, there's always Perl.
-
Re:Kids today...... :-)
-
Re:Does Python have "goto" yet?