4 ms·
It's easy to read and it just makes more sense when someone only knows English. I could show this to my 80 year old grandmother and have her understand what it
by Igglyboo 12y ago
It's easy to read and it just makes more sense when someone only knows English.
I could show this to my 80 year old grandmother and have her understand what it does with minimal help on my part.
word_list = ["hat", "dog", "cat"]
for word in word_list:
print(word)
The same example in Java isn't extremely hard to understand, but it definitely is a decent jump in complexity from the almost plain English syntax of Python.
String[] word_list = {"hat", "dog", "cat"}
for(int i=0; i < word_list.length; i++){
System.out.println(word_list[i]);
}
EDIT: Forgot about Java's foreach operator, but even so with java you then have to explain what String[] means and the keyword "in" makes for an easier read than (String string: strings) and System.out.println vs print
String[] word_list = {"hat", "dog", "cat"}
for(String word: wordlist){
System.out.println(word);
}
- Dewie 12y agoTo be fair, couldn't you use java's foreach instead of the regular for-loop? It makes things a bit less noisy.
- valarauca1 12y agoString[] word_list = {"hat", "dog", "cat"}; for(String a: word_list) { System.out.println(a); } extra brackets but pretty identical
- mickle00 12y agoNameError: name 'string' is not defined. :) print(word) means it's even easier for grandma to understand!
- codygman 12y agomapM_ putStrLn ["hat", "dog", "cat"] I'd say the above is pretty simple if explained after: putStrLn "hello world" You don't really have to go into Monads for this to be understood/used. You can just leave it at "you use functions ending with an M if they do something like print out to the screen or get stuff from a web page".
- achal 12y agoMy first reaction to this was that this was definitely less understandable, but I realized there were two pieces to this. One is banal - mapM_ and putStrLn are not near as simple as `for' and `print' (the latter have English meanings directly). The second piece is interesting: Is something of the sort "<mapfn> <printfn> <list>" easier to explain to someone who's new to programming than "<foreach> <print>"? I've always thought the latter was easier to understand, but I'm curious which one someone who has no previous programming experience would grasp more immediately.
- codygman 12y agoRight, I think that once the concept is taught of what mapM does/means it will be easier to keep applying than something like a foreach loop. The reason being that "<mapfn> <somefn> <list>" is more declarative, whereas the foreach loop is ambiguous. Something we often take for granted is how hard it was at first to come up with what exactly we need to do or mutate inside that loop to build the right result. If nothing else, there is interesting discussion to be had ;)
- theaeolist 12y agoThis is because of lexical issues. You can define aliases for mapM_ and putStrLn and get something more approachable to the lexically challenged. repeat print ["foo"; "bar"; "etc"]
- EpicEng 12y agoWho cares? If I'm a teacher I don't want to have to update material extensively every semester / year because the language is changing rapidly. Three are plenty of good, stable languages to use.
- lmm 12y agoJava is about as stable as it gets; that foreach syntax is ten years old. And if your teaching material stuck to the old-style syntax it wouldn't be wrong, it would still work, it's just not as readable as the new style.
- EpicEng 12y agoYes, all languages change over time, butrust is still in its infancy and things have not yet settled. You really don't see the difference?
- Igglyboo 12y agoSo we should teach the students old stuff because it's easier on the teacher? This isn't history, the tech world is changing daily with new languages and technologies being created. Sticking to one curriculum because it's easier on the teacher is ridiculous.
- EpicEng 12y ago"Old stuff"? No, necessarily, but the stable stuff, yes.
- aikah 12y agoMy first language was AS3.And I'm glad it was. Types dont make things more complicated. Most languages have types and I prefer dealing with them explicitely rather than letting an interpreter do random coercion like Javascript. Types lead to cleaner programming,instead of shoving random stuffs into an untyped list,a dev has to think about data structures. Furthermore,as a non native english speaker,I dont find python more readable than staticaly typed languages like C# or Java.Especially when a codebase grows larger. I wish python was statically typed.
- zo1 12y ago"Types lead to cleaner programming,instead of shoving random stuffs into an untyped list,a dev has to think about data structures." You're more than welcome to not think about what types you put into a structure/list. You'll quickly learn how to use that list/structure without hand-holding. For 90% of the problems out there, you don't need anything other than the basic data structures, and they're pretty straightforward to use without having to think about types. Note. Please don't confuse Javascript's weak-typing with Python's typing, as Python is strongly-typed.
- dragonwriter 12y ago> Types lead to cleaner programming,instead of shoving random stuffs into an untyped list,a dev has to think about data structures. Once you've learned to think about types -- as most introductory courses, even those taught in dynamically typed languages, will teach you -- you can do that just fine in a language that doesn't put a gun to your head and force you to. (And you can do so in ways that most statically-typed languages have too limited a type system to let you do, too.)
- cma 12y agoPython doesn't do random coercion, except bool to int.
- benjiweber 12y agoIn modern Java(8) it is now asList("hat", "dog", "cat").forEach(System.out::println)