8 ms·
Overkill: Java as a first programming language (2010)
- lindgrenj6 10y agoI would partially agree with this even though Java is a great language. 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.
- joshuata 10y agoIt was even worse starting in C++. Almost half the code in any project was opaque black magic. What is char and why do I need it? Why do I need `using namespace std`? Why do I need to create a Pair in order to insert into a Map?
- x1798DE 10y agoI don't think it's worse in C++. You can make purely imperative C-like programs in C++ with essentially no boilerplate (with the exception of maybe needing io from the standard library), and build things up as they go.
- btschaegg 10y agoWhile I still am a big fan of C++, I'd attest to the fact that is a worse language to teach beginners. Funnily enough, that's not so much because of the language, but because of its legacy. 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.
- flukus 10y agoThe problem there seems to be that you were learning an IDE/Gui builder and c++ at the same time. I still think I language that exposes pointers directly (c, c++, others?) are far better than something like python. Pointers force you to understand memory, allocations, the heap and stack, etc. There are way too many professional programmers that don't understand them.
- btschaegg 10y agoThe problem there seems to be that you were learning an IDE/Gui builder and c++ at the same time. Even from a modern persective, I'd disagree with that. Yes, the IDE was a pain point, but it existed because the alternative is much worse. You don't want to start out explaining Makefiles to anyone (even if you start with VS you'll be spending an hour setting up instead of programming). Pointers force you to understand memory, allocations, the heap and stack, etc. Yeah, and we'll both agree that this is crucial knowledge for any professional programmer. But if you're starting out (we're talking first language here), it's in the way. You don't even know what a loop is yet. You're at least years away from professional. Also, not everyone who programs wants to become a software developer. Sysadmins don't need pointers, but a readable alternative to shell scripts is nice (I know such people, they exist). A journalist who wants to make a flashy chart on the internet doesn't need to know pointers. A biologist also doesn't - but (s)he can certainly benefit from programming. Have you seen what Jupyter can be used for? Edit: As a side note, I also see much value in starting with a more functional language than C++. Lexical scope really affects your thinking. If you can get to that at the end of the first course, you'll have taught something tremendously useful. I've been working at a local university of applied sciences until last year, and you really don't want to know how many students there struggle with a C++ lambda expression. Again, to reiterate: I'm a fan of C++. I still cringe at most other imperative languages. But I see its weaknesses (especially in teaching).
- flukus 10y ago> Also, not everyone who programs wants to become a software developer. Sysadmins don't need pointers, but a readable alternative to shell scripts is nice (I know such people, they exist). A journalist who wants to make a flashy chart on the internet doesn't need to know pointers. A biologist also doesn't - but (s)he can certainly benefit from programming. Have you seen what Jupyter can be used for? In context, this is about CS classes, while the others might do some programming they shouldn't need to do computer science. Also, although being easier, is jupyter doing anything not being done in emacs years ago? >You don't want to start out explaining Makefiles to anyone (even if you start with VS you'll be spending an hour setting up instead of programming) To anyone on the path of becoming a professional programmer, yes, it's worth a few minutes to write a trivial makefile. It's worth teaching how to compile from the command line and how to batch those commands with a DSL is really simple. Again, there are way to many programmers who have no idea what their IDE is doing, which really isn't that much. > Yeah, and we'll both agree that this is crucial knowledge for any professional programmer. But if you're starting out, it's in the way. You don't even know what a loop is yet. You're at least years away from professional. c/c++ don't force this straight away though, you can easily do for loops before you begin managing memory. In any language memory should be understood before arrays are.
- hackits 10y agoIt would of been better to start you with C then transitioned to C++ later on or skip it all together and go directly to java/ocamel/haskell then come back to C++ at a later date.
- alexbanks 10y agoIn my CS101 class I asked what the "public static void main(String[] args)" meant at the beginning of the java code we kept getting and got the response: "It's some magic, don't worry about it."
- kevhito 10y agoWell then your instructor was doing it wrong, and that's a shame. I teach this course regularly, in Java (and previously in C++). 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
- unexistance 10y agothanks for the much-needed perspective
- btschaegg 10y agoBut that's already the problem: You start by ignoring instead of explaining things. 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.
- alexbanks 10y agoI think you're being a little bit aggressive about the when's and the how's. I think there's nothing wrong with saying "Don't worry about that until next week, we'll be discussing that in another lecture" as long as it does in fact get explained. I don't think the statement should be "it's magic, ignore it," ever. At most universities I've seen, CS101 assumes no programming experience, so if you want to show a real Java code block there's going to be a lot of stuff a student's never seen before. I also think this is why languages with REPLs and relatively few syntax modifiers (like Python) are good for intro courses. You can fire up a REPL and type `print "Hello World"` and it'll do just that. The students don't have to see any "don't worry about it" type stuff. edit We may have been agreeing about the "print Hello World" part and the Python part. The problem is that some universities (like my Alma Mater) had the hard requirement of all CS and IT students started with Java.
- g00gler 10y agoWhat's the point in hiding the fundamentals of OOP, rather than starting with them very quickly? You can't get very far before you're calling methods on the strings you're printing. 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.
- hackits 10y agoI believe it is to teach the fundamentals of the CPU, Machine code before the student has any knowledge of the abstraction's that currently exist. Then after the fundamentals have been established introduce the abstractions and different approaches to improve productivity.
- no_wizard 10y agoThe reverse is to give people a way to build things. Even simple things. This lights up the brains response every time you get the computer to, as my old lab partner in my first CS class put it 'to do a thing! Automatically!'. 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.
- javajosh 10y agoLogo[0] was my first programming language on an Apple IIe. I was in 2nd grade and I loved it. You had subroutines, but that's it. Essentially all state was visible (although you could do increasingly more magical-seeming things the more state you hid - a truism that has held since then). It was a lovely way to see the thread of execution. 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) https://en.wikipedia.org/wiki/Logo_(programming_language) 1. https://en.wikipedia.org/wiki/Seymour_Papert https://en.wikipedia.org/wiki/Seymour_Papert 2. https://en.wikipedia.org/wiki/Mindstorms_(book) https://en.wikipedia.org/wiki/Mindstorms_(book)
- empressplay 10y agoWe feel the same way! That's why we re-created Apple LOGO with 3D [adding UP / DOWN / R(oll)L(eft) / R(oll)R(ight) commands] support to make it more palatable to modern audiences... http://octalyzer.com/downloads/ http://octalyzer.com/downloads/ Any feedback you could give would be awesome! Thanks =)
- pacaro 10y agoWhile there is nothing wrong with adding up, down, roll, pitch, and yaw commands (I guess yaw is already provided by RT and LT) it feels like you are missing the point of LOGO when you make statements like these. 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
- empressplay 10y agoWe are aware =) This is why we re-implemented the entire language syntax (not just turtle graphics).
- nxtrafalgar 10y agoI disagree with this. The second course most [software] engineering students at my university are exposed to, after basic MATLAB and C programming, is 'Object Oriented Design', which teaches the fundamentals of OOP using Java. 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.
- throwaywgsid 10y agoJava is my favorite language now, but its power comes with a lot of potentially confusing constructs. The sheer complexity of the syntax is bad for beginners as well. 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.
- agency 10y agoI'm on board with Java not being a great first language but I'm pretty tired of posts constantly citing ancient unidiomatic Java to prove how bad of a language it is. Their file i/o example could just as easily be 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.
- omn1 10y agoI don't see how this is much easier for a beginner. :)
- agency 10y agoAgain, I don't think Java is a good beginner programming language, but this version: 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.
- tps5 10y agoNothing kills a beginner's interest more than "you need to have a class and a main method, always, and I can't explain why, just trust me, you'll understand later." 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.
- 10y ago
- kovrik 10y agoI disagree. Yes, Java is verbose, but all this verbosity makes sense. 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).
- isthisnagee 10y ago> But all this verbosity makes sense 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.
- a3n 10y agoIf you're going to take CS AP classes in high school, it's gonna be Java. This probably explains why a lot of people learn Java as a "first" language. (And no, not everybody started programming when they were five.) https://apstudent.collegeboard.org/apcourse/ap-computer-science-a/course-details https://apstudent.collegeboard.org/apcourse/ap-computer-scie... https://en.wikipedia.org/wiki/AP_Computer_Science https://en.wikipedia.org/wiki/AP_Computer_Science
- hocuspocus 10y agoIn Europe I'm not aware of any country offering Java classes in high-school. It's typically Python or other languages with a low barrier to entry. Maybe JS today. 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).
- vorticalbox 10y agoHere I'm the UK visual basic is collages and universities language of choice, its out dated and not even used much in the industry. 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.
- cschmittiey 10y agoAt least at my high school, we have two classes teaching Java. 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.
- TazeTSchnitzel 10y agoIf you want something intended specifically for beginners, Microsoft's Small Basic is interesting.
- keithnz 10y agoIs great.... except the lack of support for writing your own functions. Except you can simulate it with hacks, which are confusing to kids. My son did SB at school, and the code they produced was a mess because they couldn't structure things well when they needed repeated, but slightly different things to happen, they end up copy pasting, then they have a problem and have to track down all the copy pastes, etc
- rdiddly 10y agoSeems like if you did spend the time and effort to understand all the parts of the Java example, you'd be well on your way to being a coding badass. But it's important for someone forming their first impressions to be able to have a quick turnaround from having an idea, to telling the computer to do something, to having the computer do it. That's the part that gets 'em hooked!
- shearnie 10y agoHe's deliberately made the java example of file input too busy, it's poorly written. And added multiple exception handling to make it longer than it needs to be (in its context). 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.
- javajosh 10y ago>He's deliberately made the java example of file input too busy, it's poorly written. 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.
- rubyn00bie 10y agoDisagree 100% and that's because I've helped and seen many juniors who learn ruby or JavaScript first not actually understand what they're doing. More so ruby, FWIW. 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.
- jswrenn 10y agoThe examples the author cites of having to write a great deal of code that one does not understand is the motivation for Racket's language levels [0]. 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. [0] https://docs.racket-lang.org/drracket/htdp-langs.html https://docs.racket-lang.org/drracket/htdp-langs.html
- 4258HzG 10y agoOr for younger programmers (pre-college) a learning oriented language like Processing where you can gently move into java, and get to do graphical and interactive programming quickly seems to be a better option. As a teen, the lack a excitement from learning to write to files and handle text input killed my initial enthusiasm for programming and had me go first into the sciences instead. Whereas, I still find it very satisfying to be able to make interactive graphics in a few lines of code in a way that text output or static webpages never will for me. 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.)
- MikeTheGreat 10y agoI teach Java in my "Intro To Programming For NonMajors" class. I get around the problem of "lots of boilerplate code required" by giving them a file with the boilerplate code, and then have them start writing their code in main(). It works well enough (certainly as well as having them write 10 PRINT "Hello, World!") and the students are fine with it.
- MikeTheGreat 10y agoOne thing to consider when picking a language for someone's first programming experience: students like the 'language du jour' - it motivates them. I like the idea of using Basic/Pascal/Blockly/etc (and students like how easy those are) but about 3-4 weeks in they'll start to ask "Sooooo.... does anyone actually use this for real, in industry?". This tension between wanting something easy enough that students can handle it vs. wanting something that 'real' programmers use is common. 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"
- nicolashahn 10y agoAs someone whose university had Java as their introductory course's language, I feel morally compelled to upvote this.
- rootedbox 10y agoIn my high school we learned Pascal first. OOP Pascal Second. C++ third. and C last. I am forever grateful to have learned programming in this order. It has enabled me to jump into any language and just "get things done".
- hzhou321 10y agoI think the first language course should not be any single language but a language sampling course. Students learn the concept of variables, switches, loops and subroutines, then they learn how it is used in all common languages. And for homework, they are allowed to pick their favorite. For starting programmers, language is not important, concepts are. Any specific language will skew the concept.
- glangdale 10y agoThis isn't a bad idea (Python not Java for a first language makes sense on a number of levels) but the example is setting up a straw-man. Why is the Java code handling exceptions when the Python code isn't? Why is the Java code reading the file line-by-line and the Python code isn't? 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).
- timecube 10y ago>Why is the Java code handling exceptions when the Python code isn't? Why is the Java code reading the file line-by-line and the Python code isn't? Because you have to do those things in Java. That's the entire point of this article
- deleted 10y ago[deleted]
- jaimex2 10y agoAny easy and quick language will do. 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.
- MaxLeiter 10y agoCurrently learning Java in AP Computer Science in highschool. 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)
- wellpast 10y agoStill, JVM languages are wonderful and meet this criteria. Groovy --- print "Hello World" Clojure --- (print "Hello World")
- vorg 10y agoApache Groovy meets the one-line criteria but fails the simple syntax rules criteria. In your example, you have to explain that Groovy's println syntax above only works for certain types of arguments. If you want to print a string then 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.
- RandyRanderson 10y agoSo we should start to teach ppl to fly planes by first teaching them to ride a bike? Riding a bike will not help you fly. Programming isn't hard but if "public static..." melts your mind, software may not be for you. 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).