37 points · by omn1 · 9y ago · 67 comments
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class fileIO {
public static void main(String[] args) throws IOException {
Files.copy(Paths.get("test.txt"), System.out);
}
}
Granted that Files utility was added in 2011. Even in 2010 there were plenty of better ways to write that example.Java was my first language. No one explained any of that stuff to me. And for whatever reason I lacked the agency to go figure it out for myself although I had internet access. Probably because I assumed paying attention in class and doing my homework was enough.
1. Avoids try/catch syntax, and in fact can defer mentioning exceptions entirely (at the cost of the "throws" declaration being a mystery, which the main function already is to a beginner)
2. Does not require understanding of loops. In fact their example loop is particular egregious in its use of assignment in the loop condition which is especially likely to confuse beginners who are still learning the difference between "=" and "=="
3. Does not require introduction to Java's Reader I/O abstraction
4. Does not require familiarity with null references
I'm not saying my version wouldn't be confusing for beginners, but it would be hard to write a worse version than the one they give.
I can firmly recall in my CS 101 class where they were teaching basic programming using Java, and the teacher seriously told us "just put static in all of your method declarations, don't worry about why yet otherwise you won't be able to use them in your main".
...didn't fully learn what static meant until over a year in my programming career.
Week 1: "it's just some magic, don't worry about it"
Week 2: arrays are a thing, hey look, args is an array of strings!
Week 3: functions are a thing, hey look, "void" is the return type, args is the parameter!
Week 8: objects are a thing, hey look, static mean's it's not a member of an object
Week 9: software engineering is a thing, hey look, public is an access modifier
If you start with
print("Hello world!")
you can already start explaining your subjects everything they've just written and build from there.So, you'll get around faster to teaching the mindset of programming instead of explaining access modifiers. Those are not needed for that.
Also, if you would start an explanation of anything new to me now with "oh, that's magic, just ignore it.", I still would walk away from your course if you can't explain that within a week.
Sounds like you're a really good instructor for that type of stuff. We need more of you.
I learned programming with Borland Turbo Pascal and later Delphi and have to admit I struggled with the OOP mindset at first. The according chapters of the book I used were filled with contrived examples that left me saying "I can also do this the old way!". Apart from this, I found the book to be very well written, though.
Then, I tried learning C++ (using a Book frome the same series) with Borland C++ Builder. Boy, was that a mistake. I didn't get around to understand why I had to keep using -> instead of . everywhere (before, I almost never used a pointer anywhere), the whole delete-dance was a nightmare and the Borland tooling was so filled with magical clicks that generated event handlers that I never understood how the whole thing really worked (you never got to see the whole code). Headers vs. .cpps was a similar disaster, and compiler errors could only be met with comparing your code with the example on a symbol by symbol basis[1].
So, while C++ is a nice language (far better than Java IMO), starting in it was a nightmare. The problem here is that you have to explain way too many concepts at the beginning (which still holds true even with C++17), and since APIs like the Borland GUI libraries or win32 are based on so much cruft and ages old crap, you'll never get to the point where a beginner can say "Look, I've drawn a circle!".
Honestly, if you ask me, programming courses should best just start with a modern version of Python. But even then you'll have trouble setting up on Windows and getting over the whole UI frameworks disaster.
[1]: This kills experimentation. That's the absolutely last thing you want to do if you're trying to teach a motivated kid how to program.
Edit:
Also note: Often, the mindset seems to be that "beginner" means someone at a university. In my opinion, that's a fallacy too. I started out when I was 11 - I'd never even had any decent english course in school back then. Think of that, and you'll start to see the flaws in starting out with some way too complicated concepts. We should get rid of the notion that a learner has to "push through" things (especially at the start!). It will be to the benefit of society.
I'm genuinely curious, I sat through an intro to programming & follow-up course in PHP and that line of thinking seemed to confuse the students. They weren't sure of what a function was even though they were using functions! The professor never got around to explaining OO or any fundamentals.
Fewer concepts to learn. I've worked with people who have been programming professionally for decades and still don't use OOP well. OOP is hard.
With a novice user, you want to get them making a computer do cool stuff as soon as possible with as few concepts as possible. Everything else runs the risk of scaring them away forever.
Java was the first language used when I was in school, and nobody had a problem with the "Hello World" boilerplate. The professor took about 2 minutes explaining it, told us we'd cover it later in the course (and we did), and then we jumped into the main function.
A bad teacher can teach any language poorly.
EDIT: Now that I think about it, the class was something like, "Data Structures in Java," and the main focus of the class was introducing data structures, with Java tacked on because it was popular at the time (right around y2k) and it made grading easier to have everything in the same language. After that, I don't recall there being any classes explicitly about learning particular language. There was an "Advanced Java" class, but it was an elective showing how to create GUIs and a (brief) intro to things like Java Server Pages.
My first real python program made me gush with endorphins. I feel like if I didn't start off on Python first (and, for whats it worth, still heavily use today) I wouldn't have been NEARLY as interested in the mechanics behind it (specifically the C libraries) or generally the things python lets you take advantage of (like manually managing memory. I still have horrid memories learning C and dealing with pointers.) It drove my curiosity to understand all the under the hood aspects.
If I started with Java, I wouldn't have had these wow like moments writing fairly large (at the time, anyway) programs that actually functioned. Like my first simple RSS reader. Or the first time I discovered I could automate my Macs tasks quite easily.
I was HUNGRY for power after that. and i knew, at least, more power, for all python was worth, would likely come from other languages being in the mix. So I learned Java, and C, and opened my eyes to the power of many other languages (I still insist Perl is better at string processing than any other language. Show me that its not! /rant)
I think there is a lot of value is in learning the fundamentals with Python or another interpreted / high-level language first.
From a practicality stand point of view using bash, batch files, nodejs, python is going to be faster second to none, I'm not discussing that. The point is using a low level language you have to consider about decoding the jpg, memory allocation or possible streaming issues. Optimal buffer size and command prompt parameters to parse from the command line to resize the image. All tangibly relate to other fields in the curriculum and when you get a job the field.
I started in BASIC as a kid. The barrier to entry was minimal and fun for a few hundred lines of code.
To manage the complexities of a large code base, you need to have supports and infrastructure and information hiding to structure it neatly. That adds extra code, but contains it in a way to makes sense of it all.
Do you have evidence to judge the intention of the author?
The simple truth is that good pedagogical code is hard to write in any language, but Java makes it especially hard since it makes the two most essential things, invocation and I/O, needlessly difficult. Java also makes graphics (AWT and Swing) and even something as simple as Date/Time needlessly difficult. Just about the only thing that's really outstanding in the standard library are the Collection classes (arguably util.concurrent is good too, but a) concurrency isn't for beginners and b) concurrency requires better language and runtime constraints, like those provided by Clojure or Erlang).
Java was invented for embedded devices and was supposed to be C without pointers that could run anywhere. Not quite sure how it ended up as an Enterprise Server platform. marketing, I guess.
What an amazing experience to read Papert's[1] Mind Storms[2] as an adult to understand the profound thinking behind Logo.
Why not teach Logo as the first programming language?
0. https://en.wikipedia.org/wiki/Logo_(programming_language)
http://octalyzer.com/downloads/
Any feedback you could give would be awesome! Thanks =)
The turtle graphics are great at getting you sucked in, but the language is so much more powerful than that. Logo is a lisp and can be used to do many wonderful things in addition to turtle graphics
Picking a language like Java (and handing out starter files to overcome the required verbosity) is a nice way to go - it reduces the cognitive load to something they can reasonably handle AND it keeps the motivation of using a "real world language"
Examples: in junior ruby engineer, even some mid level, the confusion between local variables and attributes causes huge amounts of confusion. I don't know how many times I've asked "why is this an instance variable?" to a response being the sound of crickets.
Things like attr_* in ruby cannot be appreciated until you know why they're there. In more verbose languages like Java you're forced to understand from the beginning. Yes, there's more to learn before you get started but once you've learned it you're capable.
Learning Java was a huge "aha!" moment for me after having spent years with ruby. I've known others who express the same.
I think developers who don't learn a language like Java first hit a very hard and tall walls at some point in their learning and advancement.
Java also is much better, IMHO, language to learn design patterns in, because there is often no shortcuts provided by syntax to "prevent" or circumvent them. Also an added bonus is that the example you're reading is likely to be in Java.
I used to think scripting languages were great for learning to program but my tune has changed as I've progressed over the last decade. I now think they inhibit learning at a certain point because they lack the rigidity needed to demonstrate more advanced techniques to the learner.
I love ruby, it's in my damn username, I just don't like it as a first language these days.
I think it is better to write more code, but be able to understand it and reason about it, than write one line and rely on all magic under the hood (having no idea how it works).
The thing is, a person learning a first programming language doesn't understand it and cannot reason about it. They're more interested in "why do we use a for loop" and "what's an int?" and less interested in "How do these static objects work?".
But I agree with you to an extent. Eventually the hand holding has to stop, we have to take the training wheels off, and they're going to have to fall a few times. But it's easier to get back up after you've had training wheels, because you know what it feels like to ride a bike.
For the college level, I agree with the writer's suggestion of Python, not just for its ease of learning, but its breadth of libraries making it useful for many science and engineering courses. However, I think that for getting advanced (fun) features early on by picking and getting the right library (working) may still be a bit too much unnecessary friction to do 'fun' programming to get earlier students engaged. Learning extra tooling and library systems is 'trivial' if you code regularly, but is still a surprising amount of work when you're new to programing and gets in the way of early feedback. (I have had colleagues in the sciences hesitate at the sight of import statements, dealing with multiple libraries, and new IDE's when suggesting using something like sci-py/python over Matlab for projects, for these sorts of reasons.)
However, it is not just a matter of Java having a syntax that imposes a lot of cognitive load on novices. It is about being able to talk basic programming language features independently from advanced languages features. This is independent of both syntactic and semantic complexity. Python's clean syntax, for example, masks some really complex semantics.
Neither Java and Python are poor programming languages, but their overriding design goals are to be languages that proficient programmers can be very productive in. The pervasive mistake in CS education seems to be that these languages are therefore great choices for teaching programming to non-programmers. They are almost certainly not.
I really hope that the discussion of languages for CS1 can move beyond this. There are many languages whose overriding design goal is to be phenomenal for introductory computing education. They are designed by computer science educators, and are shaped foremost by the observed successes and difficulties of actual students that are learning to program with them. They provide answers for educators beyond just a syntax and semantics; frequently, they come battle-tested textbooks and teaching materials.
Further, you could easily write a simple file library in almost any language that abstracts over the difficulty of using the full file library if you're looking to ease people into programming.
All that being said, Python is a pretty good first language and there's a reasonable chance that someone who does one course in Python might be able to do simple tasks later on, which is nice. I think first languages should generally either be simple scripting languages or 'hazing' languages (i.e. something weird to put everyone on a more level playing field).
Because you have to do those things in Java. That's the entire point of this article
https://apstudent.collegeboard.org/apcourse/ap-computer-scie...
One is AP Computer Science, and the other is IB Computer Science. They're taught by different teachers, and AP CS is almost purely focused on nothing but programming, while IB CS also examines how computers work, ethical issues currently in the field, etc.
However, we also have Programming and Advanced Programming, taught by another different set of teachers, that teach Visual Basic, Gamemaker Studio, and handwriting HTML. Not JS, or CSS, just HTML.
Yet most good universities stick to Java for CS101, and for good reasons imho. On the other hand, non-CS majors at my school were sent right away to "useful" languages in their field (C++ at that time, I assume Python is more common nowadays).
I finished computing science degree in may last year and every single code example was in visual basic, before that in my HND and HNC both visual basic.
Also the classic file read idiom (the C one) teaches some of the most basic things every programmer should undertand:
. file encoding (which you ignore)
. buffer sizes
. error handling (likely 80-90% of production code)
Your python example ignores these basic instructive points. Why is there no "String str=String.read(file)"? Because it's seldom useful in production (see points above).
It's very useful to have a consistent mental model of classes, methods, variable lifetimes, etc. early on.
Of course, if you're teaching yourself to program (or recommending a language for self-teaching) then Java probably isn't the way to go. However, with a competent teacher, fundamental Java knowledge can be invaluable.
I have past experience with Java/C/programming, so it's not too difficult, but a lot of my classmates struggle due to the complexity of Java. Thankfully, the AP test is mostly logic focused, but the amount of time we spend going over Java is less time we can talk about problem solving. (And the amount of time we go over topics like what "static" means is substantial)
For starting programmers, language is not important, concepts are. Any specific language will skew the concept.
I started with Visual Basic in high school, it was a great base and kept things interesting. Our teacher did a great job of giving us fun projects to develop and I think that was way more important than the language chosen.
Groovy --- print "Hello World"
Clojure --- (print "Hello World")
println "Hello World"
is being translated internally to `System.out.println("Hello World")` and therefore works. But if you want to print a list then println [1, 2, 3]
doesn't work because it's being translated to `println.getAt([1,2,3])`. You need to put parentheses around it, writing println([1, 2, 3])
to achieve the same effect. Your choice of example obscures this dirty little secret about Apache Groovy. There's many other confusing rules like this in the language, e.g. `myVariable.class` returns the class of myVariable, whereas `myVariable.clazz` returns a property called clazz.The Java example in the blog post works for all types of arguments, even if it is 5 lines long. I agree with you that Clojure meets both the one-line and simple syntax rules, though.
It's harder to create program that compiles and runs, at least until you understand compiler and syntax errors well enough to avoid them.
I learned Java as my second language after Perl and I remember how horrible it was to grok all the concepts at once.
At the same time, like I said, it's my favorite language now. The syntax, constructs, and standard library are built in a very sensible way. There's nothing I can look at in Java and say "wow this really fucking sucks" which is rare among languages. C# is the only language I can think of that definitely has cleaner design.