for loops in python are bunk

irishScott

Lifer
Oct 10, 2006
21,568
3
0
So I have to learn python for a class, and it's a decent language insofar, just encountered the first thing that makes my skin crawl: retarded for-loops (oh sorry, for "statements") Now granted I'm coming from 8 years of C/C++ and Java, but come on. If I want to make a for loop that goes from 5 to zero inclusive I have to use:

for i in range(5, -1, -1)

That's two negative numbers and a function, all to say I want to count from 5 to 0.


Contrast to:

for(int i = 5; i >= 0; i--)

Nice and explicit. You have the variable and its initial value, the explicit limit of the variable without having to look up weather "range" or some other function is inclusive or not, followed by the interval of the variable.

Don't tell this to my recent PhD professor though. He keeps expounding on how ugly and dirty everything c++ is. Because obviously the last thing anyone wants in code is detail :rolleyes: /rant
 

postmortemIA

Diamond Member
Jul 11, 2006
7,720
39
91
it is just semantics, does not make programming language that bad. python is quick and dirty way to get something done. bordeline scripting language.
 

irishScott

Lifer
Oct 10, 2006
21,568
3
0
it is just semantics, does not make programming language that bad. python is quick and dirty way to get something done. bordeline scripting language.
Yeah, but it pisses me off all the same. It makes code less readable, which I thought was contrary to the Python ethos (and good coding technique for that matter). :p

Don't get me wrong there's actually plenty I like about the language from an ease-of-use standpoint, and I'm loving Komodo Edit. Just a frustrating nitpick.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
The python for loop is better compared to a C++ for_each loop (or the Java equivalent). In reality you're iterating over a list of integers (or an interator that returns integers), which is just a special case of the for_each in C++. If you write your C++ code with that in mind you'll see that it isn't so nice.

And I don't understand your argument otherwise. The range() function is not hard to understand or remember, and functions are not inherently bad things. The nice thing about range() is that you always know how many iterations you're doing since you just subtract the first two numbers (unlike in C++ where you have to perceptive of < vs <=).

In short, your rant sucks and reeks of someone who thinks in one paradigm because he's never had to code in another. Go learn Lisp or something, it'll open your mind.
 

irishScott

Lifer
Oct 10, 2006
21,568
3
0
The python for loop is better compared to a C++ for_each loop (or the Java equivalent). In reality you're iterating over a list of integers (or an interator that returns integers), which is just a special case of the for_each in C++. If you write your C++ code with that in mind you'll see that it isn't so nice.

And I don't understand your argument otherwise. The range() function is not hard to understand or remember, and functions are not inherently bad things. The nice thing about range() is that you always know how many iterations you're doing since you just subtract the first two numbers (unlike in C++ where you have to perceptive of < vs <=).

In short, your rant sucks and reeks of someone who thinks in one paradigm because he's never had to code in another. Go learn Lisp or something, it'll open your mind.
Sorry you took my rant so seriously. Guess I should have known to expect that outside of OT.

Is the range function any serious impediment? Of course not. Is it a gnat occasionally buzzing around my head? Yes, yes it is. Hence the reason I made a rant and not a serious argument.

I shouldn't have to remember even a simple function to make the most basic loop known to man. Also I find it far easier to instantaneously discern "<" vs "<=" than to stop and do x seconds of unnecessary mental subtraction. There is nothing nice about the range function with respect to loops over its c/c++/java counterparts IMO. If mental math is somehow easier for you than visually discerning basic logic symbols, perhaps you have a point.

When I have, find, or am assigned a use for Lisp, I'll look it up.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
I think you missed my point about the subtracting vs </<= thing. In C++ you have to subtract AND be aware of </<=.

For example, for (int i = 0; i < 5; i++) produces 5 iterations, while of course for (int i = 0; i <= 5; i++) produces 6 iterations.

In python, range(5) produces 5 iterations and range(6) produces 6 iterations. It forces consistency which tends to make things more easily understood.

I guess my point is that the only reason you feel range() is a gnat is because you are fixated on plain C-style coding. If you think about python loops as C++ for_each loops over iterators, then it all makes sense (you need something to construct an iterator over integers, so why not a range() function?).
 

Cerb

Elite Member
Aug 26, 2000
17,484
33
86
I like synactic sugar for this sort of thing:
Code:
for i in 5 to 0, -1
or forced recursion (impure functional languages FTW!), for scripting, but Python's isn't that bad.

Python's ethos cannot be being easy to read, because it only wins in that regard over classic VB or worse. While far from my favorite language, Ruby at least does that part right. Python's main advantages are that it's (a) generally better than perl, bash, or PHP, for general use, and (b) it's quick and easy to get started with, and (c) quickly whip up simple programs with, without code complexity turning against you as it grows.
 

Pia

Golden Member
Feb 28, 2008
1,563
0
0
If you code in Python, you have to know the semantics of range(). You don't "look them up" any more than you "look up" the order of statements going inside a C-style for statement when coding C. And yes, people do put them in the wrong order, and they also make hard-to-see errors with subtle changes in indexing, accidentally using one of < > <= >= == when they meant another, etc. I can say from practical experience with hundreds of university students learning C that the C-style for statement is both harder to read and more error prone. It's not by accident that C++11 introduces a range based for statement.

In your particular Python use case, you could use
for i in reversed(range(6))
which is compact, requires no mental math and offers little chance for error.

Range() being exclusive might be a surprise to a newbie but should be expected by a person used to programming. The normal thing to do, also in C++ or Java, is to iterate from 0 to n-1 for some thing of size n, and that is what range(n) gives you. C++ end iterators work analogously, being out of the range.
 

irishScott

Lifer
Oct 10, 2006
21,568
3
0
If you code in Python, you have to know the semantics of range(). You don't "look them up" any more than you "look up" the order of statements going inside a C-style for statement when coding C. And yes, people do put them in the wrong order, and they also make hard-to-see errors with subtle changes in indexing, accidentally using one of < > <= >= == when they meant another, etc. I can say from practical experience with hundreds of university students learning C that the C-style for statement is both harder to read and more error prone. It's not by accident that C++11 introduces a range based for statement.

In your particular Python use case, you could use
for i in reversed(range(6))
which is compact, requires no mental math and offers little chance for error.

Range() being exclusive might be a surprise to a newbie but should be expected by a person used to programming. The normal thing to do, also in C++ or Java, is to iterate from 0 to n-1 for some thing of size n, and that is what range(n) gives you. C++ end iterators work analogously, being out of the range.
*sigh* Wonder how many more people are going to jump down my throat for my meaningless rant on a miniscule piece of syntax that I personally find mildly annoying; and I have a right to find it mildly annoying, the same way I have a right to find someone's handwriting style mildly annoying even if it is perfectly legible after some inspection.

I never argued that c-style loops were easier to learn for someone who's never programmed before, or that people don't make mistakes. Even experienced programmers make plenty of them, regardless of the language. That said I started by learning Java as a sophomore in high school, in summer school no less. It was hard, but somehow I and all 20 some-odd of my classmates had mastered loops and then some by the end of 2.5 months. :p This was in public school BTW.

From an educational standpoint I've never understood the point of using a relatively "simple" introductory language for anyone over the age of 16. If someone, especially in college, wants to learn programming it's likely they intend to use it at some point in their career. Now granted Python isn't a useless language, but it's far less ubiquitous than c/c++/java. I'd say the students who actually give a damn would be better served and display increased motivation by being taught a language that they're more likely to use, and being told as such. Anyone who can program in BASIC, Python, or any other likely introductory language can program in c/c++/Java. The difficulty curve is merely a matter of time and proper pacing.


Now as for reversed, aside from being mildly less readable I find the presence of concentric functions in a basic loop to be visually repugnant. I look at it and I think "dirty code" and "inefficient". You may look at it and think "Mona Lisa". Whatever.
 
Last edited:

irishScott

Lifer
Oct 10, 2006
21,568
3
0
I think you missed my point about the subtracting vs </<= thing. In C++ you have to subtract AND be aware of </<=.

For example, for (int i = 0; i < 5; i++) produces 5 iterations, while of course for (int i = 0; i <= 5; i++) produces 6 iterations.

In python, range(5) produces 5 iterations and range(6) produces 6 iterations. It forces consistency which tends to make things more easily understood.

I guess my point is that the only reason you feel range() is a gnat is because you are fixated on plain C-style coding. If you think about python loops as C++ for_each loops over iterators, then it all makes sense (you need something to construct an iterator over integers, so why not a range() function?).
You do? On a basic level I just visually scan the loop. "0 to < n - 1"? "1 to <= n"? other? And unless the loop is doing something out of the ordinary there's little to no mental math involved in understanding the loop statement itself; assuming I'm looking over correct code.

I never argued that there wasn't some good technical reason for a range function, just that it mildly irks me from a syntactical standpoint. I'm certainly not in a position to question Guido van Rossum. :p
 

Obsoleet

Platinum Member
Oct 2, 2007
2,181
1
0
From an educational standpoint I've never understood the point of using a relatively "simple" introductory language for anyone over the age of 16. If someone, especially in college, wants to learn programming it's likely they intend to use it at some point in their career. Now granted Python isn't a useless language, but it's far less ubiquitous than c/c++/java. I'd say the students who actually give a damn would be better served and display increased motivation by being taught a language that they're more likely to use, and being told as such. Anyone who can program in BASIC, Python, or any other likely introductory language can program in c/c++/Java. The difficulty curve is merely a matter of time and proper pacing.
Not to bore you with an introduction but I'm essentially learning my first programming language now and I chose a 'simple' intro language, Python. I think I'm probably ~10 years older than you but when I was young I started teaching myself QBASIC, later on the internet hit it big and Geocities and the rest were popular and I got an introduction to HTML and whatever else creating pages. I didn't really master anything but certainly got a taste of what was to come. Then in high school VB6 was all the rage (awesome, I know). I took courses at the local liberal arts college in replacement of the HS CS courses (which were only moderately more advanced in the end).
After that while in college I used Coldfusion, JS, HTML to create a fairly simple webapp (the JS got a little complex considering I had next to zero exposure to it but I figured it out).

Today I work in a webdev shop, I dabble in a lot to varying degrees of capacity. For my career, Python is actually usable in systems scripting, intranet apps, and opens up doors to 3D apps built on it, crossplatform GUI apps, you name it. It opens up a ton of doors with a RAD way. Completely open source, not tied at the roots to a single provider like Java or C#.. all the tools and everything else is free. Yet Google is behind it in a big way. It seems a lot of the brightest professional devs are behind it as well, tons of libraries and frameworks sitting out there, not to mention a ton of Linux software is written in it. I'm not defending Python, it stands on its own as a relative giant considering it's non-corporate roots.

I do want to learn to at least parse through C code, but I don't think C/C++/Java are practical for someone like me or another learner who might not move too far beyond the introductory language. If I were to devote time into something else, I'd look into another win/win language, and finally master JavaScript for use with frontend work and Node. It's not quite as versatile and doesn't open as many doors as Python does though.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
From an educational standpoint I've never understood the point of using a relatively "simple" introductory language for anyone over the age of 16. If someone, especially in college, wants to learn programming it's likely they intend to use it at some point in their career. Now granted Python isn't a useless language, but it's far less ubiquitous than c/c++/java. I'd say the students who actually give a damn would be better served and display increased motivation by being taught a language that they're more likely to use, and being told as such. Anyone who can program in BASIC, Python, or any other likely introductory language can program in c/c++/Java. The difficulty curve is merely a matter of time and proper pacing.
Learning a language is really not the primary purpose of a CS education. The language is a tool to teach you concepts like functions, data structures, algorithms, recursion, and whatever else. If you can teach that without forcing students to deal with seg faults and compiler quirks, I would say that's a good thing. Sure students going into industry will have to deal with those things eventually, but in an introductory course that may be taken by a broad range of students, you'd rather focus on the computer science, not the computer. With that foundation you can learn any language.

Heck, think about the first day of a class on C vs Python. Your hello world in C looks like this:

Code:
#include<stdio.h>

int main() {
  printf("Hello, world!\n");
  return 0;
}
whereas in Python (2.x) you have:

Code:
print "Hello, world!"
Sure you can teach an introductory course with C, but you'll either waste a lot of time explaining minutiae (what's stdio? What's main()? What's int? What's printf? What's return? What's compiling? How do I run this?) or hand-waving over everything (we'll learn about that later...).

Just to give you some idea of my history, I started learning about programming with VB and then Java in 7th-8th grade (this is when Java was pretty new), then learned Perl and some C, C++, and asm in HS, then took a pretty full curriculum in college. I learned Python, PHP, and Tcl on the side in college. Only new language I got in class was Scheme (well, Verilog too).

And in my current job I use C++ and Python every day (and sometimes C for kernel stuff).

You do? On a basic level I just visually scan the loop. "0 to < n - 1"? "1 to <= n"? other? And unless the loop is doing something out of the ordinary there's little to no mental math involved in understanding the loop statement itself; assuming I'm looking over correct code.
I'm saying that one must do so in the general case. I.e., in C,

Code:
for (int i = A; A < B, i++); // Does B - A iterations
for (int i = A; A <= B; i++); // Does B - A + 1 iterations
Code:
for i in range(A, B) # Does B - A iterations
for i in range(A, B + 1) # Does B - A + 1 iterations
 

Pia

Golden Member
Feb 28, 2008
1,563
0
0
Obsoleet and esun explained it pretty well but I'll make a few points.

1) You need a beginning programmer to learn what programs are and how to structure them. Everything else is a distraction. C++ and Java are terrible choices because of their bulk, while C and C++ are terrible because of how easily you can shoot yourself in the foot with them. There are papers showing a surprisingly rapid real world advantage to starting from something else. For instance, there's a paper from the HtDP crew outlining how students coming from a Scheme course produced better results at a Java course than students whose first course was also in Java.

2) Especially in individual, non-organized learning, you need motivation and that means the language should preferably let you do interesting and cool things very quickly. Python, with its easy to use libraries, fits the bill. C, C++ and Java do not.

3) Python is a real-world language and usable for real work. It has one of the best library collections in the business, and it's suitable to use as a high level glue language with something else, such as C. You can also have it on top of JVM (Jython) and CLR (IronPython), and access libraries in those environments.
 

irishScott

Lifer
Oct 10, 2006
21,568
3
0
Learning a language is really not the primary purpose of a CS education. The language is a tool to teach you concepts like functions, data structures, algorithms, recursion, and whatever else. If you can teach that without forcing students to deal with seg faults and compiler quirks, I would say that's a good thing. Sure students going into industry will have to deal with those things eventually, but in an introductory course that may be taken by a broad range of students, you'd rather focus on the computer science, not the computer. With that foundation you can learn any language.

Heck, think about the first day of a class on C vs Python. Your hello world in C looks like this:

Code:
#include<stdio.h>

int main() {
  printf("Hello, world!\n");
  return 0;
}
whereas in Python (2.x) you have:

Code:
print "Hello, world!"
Sure you can teach an introductory course with C, but you'll either waste a lot of time explaining minutiae (what's stdio? What's main()? What's int? What's printf? What's return? What's compiling? How do I run this?) or hand-waving over everything (we'll learn about that later...).

Just to give you some idea of my history, I started learning about programming with VB and then Java in 7th-8th grade (this is when Java was pretty new), then learned Perl and some C, C++, and asm in HS, then took a pretty full curriculum in college. I learned Python, PHP, and Tcl on the side in college. Only new language I got in class was Scheme (well, Verilog too).

And in my current job I use C++ and Python every day (and sometimes C for kernel stuff).



I'm saying that one must do so in the general case. I.e., in C,

Code:
for (int i = A; A < B, i++); // Does B - A iterations
for (int i = A; A <= B; i++); // Does B - A + 1 iterations
Code:
for i in range(A, B) # Does B - A iterations
for i in range(A, B + 1) # Does B - A + 1 iterations
And that's why you need a good instructor/curriculum.

Back in high school when I was starting out with Java, we didn't start with anything resembling hello world. What we started with was a couple thousand lines of stock code designed to generate mazes and a virtual "robot" named JKarel who had to navigate said mazes. Our first task was to go to a portion of the stock code and use functions to move JKarel around. (karel.turnLeft(), karel.turnRight(), karel.move()) and such. So by the end of the first day we had a very good conceptual understanding of a function, something many traditional programs don't reach until the 2nd week. By the end of the first 3 weeks we were into game-of-life simulations, programming various classes of fish with different traits and watching the animated simulations (provided by stock code). In addition to the concepts of coding, at this point we were largely given a task and left on our own, which taught us how to scan code and look for the parts we needed; as well as make constant reference of the Java documentation. Vital skills for any programmer. This was all as a sophomore in high school with no prior programming experience (unless you count Lego Mindstorms).

The program effectively did what you describe as Python's advantage as an intro language. Abstracted the complicated stuff and let us focus on concepts early on. Only in our case we were eventually moved up to some advanced concepts, and most of the stock code that had been mystifying before was extremely clear by the end. I can't say anything resembling the same for the Python-based course I'm in now. Sure the language is easier to teach traditionally, and people are learning the basics; but looking at the course calendar, unless the pace significantly picks up I bet no one taking it as their first course is going to know what a class is, and will be all but completely stupefied if you put "public static void main(String[] args)" in front of them; even at the end of the course.


As for loops, on paper yes the subtraction is there. In practice (for me at least) it's usually a visual scan and no more mathematical than reading a word on a page.
 
Last edited:

irishScott

Lifer
Oct 10, 2006
21,568
3
0
Obsoleet and esun explained it pretty well but I'll make a few points.

1) You need a beginning programmer to learn what programs are and how to structure them. Everything else is a distraction. C++ and Java are terrible choices because of their bulk, while C and C++ are terrible because of how easily you can shoot yourself in the foot with them. There are papers showing a surprisingly rapid real world advantage to starting from something else. For instance, there's a paper from the HtDP crew outlining how students coming from a Scheme course produced better results at a Java course than students whose first course was also in Java.

2) Especially in individual, non-organized learning, you need motivation and that means the language should preferably let you do interesting and cool things very quickly. Python, with its easy to use libraries, fits the bill. C, C++ and Java do not.

3) Python is a real-world language and usable for real work. It has one of the best library collections in the business, and it's suitable to use as a high level glue language with something else, such as C. You can also have it on top of JVM (Jython) and CLR (IronPython), and access libraries in those environments.
1. I'd say that depends on the quality/nature of the program and instructor. See recent response to esun.

2. Granted, but I can say right now the most "interesting" thing we've done is move a little Zelda sprite around a blank screen. Said sprite was provided by stock code; we're not doing the cool stuff ourselves, it's being provided.

3. Never meant to imply Python wasn't worth learning or useless. Just that it's still something of a niche language. It's like learning to drive a motorcycle before learning to drive a car IMO.
 

irishScott

Lifer
Oct 10, 2006
21,568
3
0
Not to bore you with an introduction but I'm essentially learning my first programming language now and I chose a 'simple' intro language, Python. I think I'm probably ~10 years older than you but when I was young I started teaching myself QBASIC, later on the internet hit it big and Geocities and the rest were popular and I got an introduction to HTML and whatever else creating pages. I didn't really master anything but certainly got a taste of what was to come. Then in high school VB6 was all the rage (awesome, I know). I took courses at the local liberal arts college in replacement of the HS CS courses (which were only moderately more advanced in the end).
After that while in college I used Coldfusion, JS, HTML to create a fairly simple webapp (the JS got a little complex considering I had next to zero exposure to it but I figured it out).

Today I work in a webdev shop, I dabble in a lot to varying degrees of capacity. For my career, Python is actually usable in systems scripting, intranet apps, and opens up doors to 3D apps built on it, crossplatform GUI apps, you name it. It opens up a ton of doors with a RAD way. Completely open source, not tied at the roots to a single provider like Java or C#.. all the tools and everything else is free. Yet Google is behind it in a big way. It seems a lot of the brightest professional devs are behind it as well, tons of libraries and frameworks sitting out there, not to mention a ton of Linux software is written in it. I'm not defending Python, it stands on its own as a relative giant considering it's non-corporate roots.

I do want to learn to at least parse through C code, but I don't think C/C++/Java are practical for someone like me or another learner who might not move too far beyond the introductory language. If I were to devote time into something else, I'd look into another win/win language, and finally master JavaScript for use with frontend work and Node. It's not quite as versatile and doesn't open as many doors as Python does though.
Well I'd say you're not really the kind of person I'm talking about. C/C++/Java isn't for everyone or every use by a longshot, but I imagine most people entering into a traditional college-level computer science education intend, at least at the point of enrollment, to take it beyond the intro level. If you're not going to ever take anything beyond the intro level, then almost any language would suffice as a first so long as it was practical for your intended use.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Damn you're stubborn. I'll give you that the education stuff is subjective, but you're still reluctant to admit that taking the difference of two arbitrary integers requires subtraction.

Anyway, knowing what public static void main(String[] args) means is pretty useless. I'd much rather come out of a course understanding objects, scope, datatypes, methods, and arrays than the syntax that Java uses to indicate the starting point of execution. Because then I can look a construct in any language, read up on what the keywords are, and understand it.

Here's the problem with your comparison: you're comparing how you were taught Java with how you are being taught Python. I'm trying to compare how, ideally, one might teach an introductory CS course with Java and how one might teach an introductory CS course with Python.

Sure, your current curriculum and/or instructor may suck and skip over OOP. That's not Python's fault. You can teach complicated concepts in Python as well as in Java. Perhaps static typing and compilation are two things you see in Java and not in Python, but those aren't exactly core CS concepts (though they make development much less rapid typically).

Here's a thought: I highly doubt many students after your first Java class went home, downloaded the Java SDK, wrote a program from scratch, compiled it, ran it, and played around with it. I bet a much larger number went home after your first Python class, downloaded the Python interpreter, and started typing commands in to see what they would do.
 

Pia

Golden Member
Feb 28, 2008
1,563
0
0
1. I'd say that depends on the quality/nature of the program and instructor. See recent response to esun.
No for quality, yes for nature of the program. You were making a judgment/comparison of languages for teaching purposes. That makes no sense unless we assume equivalent instructor quality. Nature of the program can be relevant (if a student is only ever going to take one course, and all they intend to do afterwards is Matlab coding, the optimal course would use Matlab) but not at all in the way you suggest. In the HtDP paper I referred to, it was actually the students with most aptitude for programming who most benefited from the use of a good teaching language at first, moving on to a production language only afterwards.
2. Granted, but I can say right now the most "interesting" thing we've done is move a little Zelda sprite around a blank screen. Said sprite was provided by stock code; we're not doing the cool stuff ourselves, it's being provided.
The first problem with this is, we can't really infer much from what is being done on the course without knowing what the purpose of the course is. You never said what the topic is, only that you must learn Python.

Being able to make the computer do visible stuff is in itself very cool. There is plenty of time to DIY sprites - say, on a computer graphics course.
 

Pia

Golden Member
Feb 28, 2008
1,563
0
0
Back in high school when I was starting out with Java, we didn't start with anything resembling hello world. What we started with was a couple thousand lines of stock code designed to generate mazes and a virtual "robot" named JKarel who had to navigate said mazes.
So the course was making an effort of providing visual feedback via libraries/frameworks. Fine so far.
So by the end of the first day we had a very good conceptual understanding of a function, something many traditional programs don't reach until the 2nd week.
???
By the end of the first 3 weeks we were into game-of-life simulations, programming various classes of fish with different traits and watching the animated simulations (provided by stock code). In addition to the concepts of coding, at this point we were largely given a task and left on our own, which taught us how to scan code and look for the parts we needed; as well as make constant reference of the Java documentation. Vital skills for any programmer.
This stinks of bad curriculum and/or drawbacks of a poor teaching language. When you actually understand what you are doing - which happens slower if you are hindered by syntax quirks or having to look up documentation - there is no actual skill in looking up documentation. Raising that up as some kind of high point is like praising a driver's ed curriculum for teaching the students to tell the difference between V6 and V8 based on sound on the first day.
Sure the language is easier to teach traditionally, and people are learning the basics; but looking at the course calendar, unless the pace significantly picks up I bet no one taking it as their first course is going to know what a class is, and will be all but completely stupefied if you put "public static void main(String[] args)" in front of them; even at the end of the course.
It actually sounds like a good sign to me if an introductory course doesn't dwell much on classes, because there are so many more fundamental things students should understand first. If classes are taught early, it is likely by rote and not driven by a functional need which would facilitate understanding - why, when and how to use a class.
No idea what the "traditional" teaching is which you refer to.
 

irishScott

Lifer
Oct 10, 2006
21,568
3
0
So the course was making an effort of providing visual feedback via libraries/frameworks. Fine so far.???
This stinks of bad curriculum and/or drawbacks of a poor teaching language. When you actually understand what you are doing - which happens slower if you are hindered by syntax quirks or having to look up documentation - there is no actual skill in looking up documentation. Raising that up as some kind of high point is like praising a driver's ed curriculum for teaching the students to tell the difference between V6 and V8 based on sound on the first day.
It actually sounds like a good sign to me if an introductory course doesn't dwell much on classes, because there are so many more fundamental things students should understand first. If classes are taught early, it is likely by rote and not driven by a functional need which would facilitate understanding - why, when and how to use a class.
No idea what the "traditional" teaching is which you refer to.
Then I'm explaining it badly. We were given some preliminary explanation and instruction, but it was largely conceptual. The lab would then give us some specific tasks to do and we often referred to the documentation to accomplish it. I hold this up because we were in 10th grade and most of us had never seen a scrap of code before. Learning to navigate documentation at that early stage was a huge breakthrough. Note this wasn't just by necessity, our instructor and assignments constantly referred us to documentation. The skills acquired doing so have been useful to this day.

As for classes, learning when and how to use classes is like learning when and how to use furniture. It's not that hard, and the game-of-life simulations gave a perfect context. We were simulating different species of fish, each species had a class. Sometimes in the simulations fish would mate and their offspring inherited traits (this was used to teach accessor/mutator methods and copy constructors as well as inheritance). It was a perfect analogy and a perfect example.

I'm probably still explaining it badly, but at the end of the day it did a very good job setting me up for AP Computer Science (also in Java at the time), which in turn did a very good job of setting me up for college. You may disagree with its methods (pun intended) but it worked, and not just for me.

The "traditional" teaching I refer to is a version of what you can find in most self-help books. Starts off with a little background, then hello world, then variables, then conditionals, loops, then functions, etc, explaining all individually and technically. This is fine, especially for experienced programmers, but it isn't necessarily the best for an intro curriculum IMO.
 
Last edited:

irishScott

Lifer
Oct 10, 2006
21,568
3
0
No for quality, yes for nature of the program. You were making a judgment/comparison of languages for teaching purposes. That makes no sense unless we assume equivalent instructor quality. Nature of the program can be relevant (if a student is only ever going to take one course, and all they intend to do afterwards is Matlab coding, the optimal course would use Matlab) but not at all in the way you suggest. In the HtDP paper I referred to, it was actually the students with most aptitude for programming who most benefited from the use of a good teaching language at first, moving on to a production language only afterwards.
The first problem with this is, we can't really infer much from what is being done on the course without knowing what the purpose of the course is. You never said what the topic is, only that you must learn Python.

Being able to make the computer do visible stuff is in itself very cool. There is plenty of time to DIY sprites - say, on a computer graphics course.
Maybe so. I haven't read the paper. *shrug*

The course in question is "Into to Computer Science for Engineers". I'm actually re-taking it as I was a lazy freshman and now that I can ace it hands down I can turn a C into an A (via grade forgiveness). It also has an interesting history. It was originally 90% Matlab, 10% C++. Now it's 90% Python, 10% Matlab. The next course is 100% Java (used to be 100% c++), and it's not until Data structures (B-trees, vectors, maps, graphs and such) and higher that the average student hits c++.

Moving a Zelda Sprite on the screen is... OK. I'm not saying we should be doing DIY sprites, but that's the "coolest" thing we've done thus far. Everything else has been pretty dry. I'm enjoying Python's built-in unit testing, but I'm pretty sure I'm the only one other than the professor who thinks that's "cool". Now going back to my Java intro course, moving virtual robots through mazes and game of life simulations was "cool".
 
Last edited:

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
Personally I think Python's for loop is pretty horrid, but then so is C's, Java's and a host of other languages loops. I am moderately happy with my OO/FP hybrid loops in Scala:
Code:
1 to 10 foreach {
  i=> println(i)
}
and to accumulate a list of results:
Code:
1 to 10 map{
  i=> i*i
}
Which gives me a List of 2->20

Its also for this reason why personally I prefer Ruby as a language for beginners over Python. Ruby is a lot more readable with its syntax and more consistent with its semantics.

Code:
for i in 0..5
   puts "Value of local variable is #{i}"
end
Is quite readable and syntax light
 
Last edited:

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Personally I think Python's for loop is pretty horrid, but then so is C's, Java's and a host of other languages loops. I am moderately happy with my OO/FP hybrid loops in Scala:
Code:
1 to 10 foreach {
  i=> println(i)
}
and to accumulate a list of results:
Code:
1 to 10 map{
  i=> i*i
}
Which gives me a List of 2->20

Its also for this reason why personally I prefer Ruby as a language for beginners over Python. Ruby is a lot more readable with its syntax and more consistent with its semantics.

Code:
for i in 0..5
   puts "Value of local variable is #{i}"
end
Is quite readable and syntax light
2->20? That's some interesting math. Also I'd be careful calling that accumulating, that's a pretty specific term in FP very distinct from mapping.

I have to say I have no clue what point you're trying to make with that snippet of Ruby (frankly also the Scala, unless you think minimizing keywords should be the goal of a language). The Python version is very similar. And if you want really light syntax, there are "better" languages for that:

print for (0..5);
 

Borkil

Senior member
Sep 7, 2006
248
0
0
i took a python class a while ago and after coming from C, i too was at first annoyed at the syntax. but now i can write a script in 5 mins that would take me a week to do in C!
 

ASK THE COMMUNITY