
Overkill: Java as a first programming language (2010) - omn1
http://matthias-endler.de/2010/overkill-java-as-a-first-programming-language/
======
agency
I'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.

~~~
tps5
Nothing 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.

~~~
agency
I agree. I don't believe Java is a good first programming language. I'm just
tired of posts bashing Java by citing code that doesn't take advantage of any
of the improvements in the language since 1.4.

------
lindgrenj6
I 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
It 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
I 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
While 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
The 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

      The 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
> 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.

~~~
btschaegg
> Also, although being easier, is jupyter doing anything not being done in
> emacs years ago?

While I already think it's worthwhile that you can sidestep emacs' setup and
learning curve for uninterested students, you might be interested in how it is
already used for collaboration and teaching.

One list of examples might be this:

[https://github.com/jupyter/jupyter/wiki/A-gallery-of-
interes...](https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-
Jupyter-Notebooks)

If you're teaching math or physics to a bunch of students who know Python and
SciPy, I would assume Jupyter notebooks are an amazing way to distribute
course material.

~~~
flukus
Clicking on a few random ones seemed to be broken in the web view, which
doesn't bode well ;)

I'm sold on the idea though. 20 years ago all our math books came with basic
programs in each section, I can't help but think maths and physics would have
been much more fun if we'd been able to run them or had something like
jupyter. I've been told textbooks don't come with this any more, which seems
like a shame now that computing devices are so ubiquitous.

------
g00gler
What'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.

~~~
omn1
It's not about hiding OOP, it's about being overwhelmed with too many new
concepts at the same time. Put yourself in the shoes of a beginner: the
runtime, the IDE, the language keywords,... everything is new to them. Once
you know your way around simple functions you can start adding another layer
of abstraction. But slowly. Maybe Ruby would be an easier start for OOP than
Java.

~~~
jlarocco
Just my opinion, but it seems that starting off all at once with the language
runtime, "Hello World", an IDE, and language keywords will cause more
confusion than a few extra lines of code.

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.

------
shearnie
He'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
_> 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.

------
javajosh
Logo[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
We 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
While 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
We are aware =) This is why we re-implemented the entire language syntax (not
just turtle graphics).

------
MikeTheGreat
One 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"

------
rubyn00bie
Disagree 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.

------
kovrik
I 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
> 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.

------
4258HzG
Or 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.)

------
jswrenn
The 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)

------
glangdale
This 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
>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

------
a3n
If 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-
scie...](https://apstudent.collegeboard.org/apcourse/ap-computer-
science-a/course-details)

[https://en.wikipedia.org/wiki/AP_Computer_Science](https://en.wikipedia.org/wiki/AP_Computer_Science)

~~~
hocuspocus
In 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
Here 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.

------
RandyRanderson
So 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).

------
nxtrafalgar
I 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.

------
MaxLeiter
Currently 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)

------
rdiddly
Seems 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!

------
MikeTheGreat
I 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.

------
hzhou321
I 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.

------
jaimex2
Any 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.

------
rootedbox
In 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".

------
nicolashahn
As someone whose university had Java as their introductory course's language,
I feel morally compelled to upvote this.

------
TazeTSchnitzel
If you want something intended specifically for beginners, Microsoft's Small
Basic is interesting.

~~~
keithnz
Is 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

------
wellpast
Still, JVM languages are wonderful and meet this criteria.

Groovy \--- print "Hello World"

Clojure \--- (print "Hello World")

~~~
vorg
Apache 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.

------
throwaywgsid
Java 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.

