Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"If those who construct the curriculum want the beginning courses to focus on algorithmic thinking, I think it's fair to use a language that abstracts away much of the physical machine. The abstractions can be peeled away in later courses."

I don't know that Java does this all the much better than C. The problem with C for a beginning student isn't so much that you have to manage memory manually--it generally takes a few weeks to even get to malloc() in a C-based introductory course--but that C gets in your way with explicit typing, #includes, etc. Java does away with some of that but introduces its own OO scaffolding to get in your way too. Instead of having to write main()s and #include's, the Java student has to enclose their functions in a class and so forth. Let's compare Hello World in C, Java, and C#.

C:

  #include <stdio.h>

  int main(void)
  {
    printf("Hello, World!\n");
    return 0;
  }
Java:

  class HelloWorldApp
  {
    public static void main(String[] args)
    {
      System.out.println("Hello World!"); // Display the string
    }
  }
C#:

  class Hello 
  {
     static void Main() 
     {
        System.Console.WriteLine("Hello World!");
     }
  }
The Java and C# examples are even more cluttered than the C example when it comes to superfluous tokens: it has a class declaration, the method signature is more unnecessarily elaborate, and the print command has like three levels of object-drilldown in it. When you get to the simple procedural programs that a beginning student will write, this mysterious crud remains unresolved for longer. It's not enough to explain typing as you would in C or Pascal, but you have to talk about object-oriented programming before you get into problems complex enough to justify that level of abstraction.

If you really want an abstract language to enforce algorithmic thinking, pick one that doesn't have all that extra mental burden when you first approach it.

Perl 5.8

  print "Hello World!\n"
Perl 5.10

  say "Hello World!"
Python

  print "Hello World!"
Ruby

  print "Hello World!"
The cool thing is that these languages still have subroutines and classes and so forth, but they don't force you to declare a class, declare a subroutine, and call an object method just to code "hello world".

Java has advantages over C. These advantages don't include "letting beginning programmers focus on algorithmic thinking by using high level abstractions". Java's higher level than C in that it protects you from naked pointers and lets you do OOP, but that's not the type of high-level abstraction that helps a beginning programmer, especially not when it comes at the cost of forcing them to put everything in classes and methods.

If those who construct the curriculum want the beginning courses to focus on algorithmic thinking, I think it's fair to use a language that abstracts away as much as possible. We have no shortage of good interpreted languages to accomplish this.



Actually I'd argue that with C, you have to start managing memory manually before you even get to malloc. The abstraction advantage of Java over C (not that I think Java is necessarily a better intro language) is that you can generally explain the syntax in abstract concepts and then use it like you'd expect. With C, it's far more likely to encounter scenarios that don't fit a simple model of understanding.

For example, unless you're concerned with specific performance issues, you're not likely to care how a string is implemented in Java. It's difficult to use strings in C without understanding memory. Without understanding when strings are mutable and when they aren't, what null-terminated means, how "%s" works, and such you will quickly run into some unexpected behavior and will likely just trial and error until you get something that seems to work. When you understand that C is a syntax for allocating and manipulating memory, it tends to make a lot more sense.


Yea, the advantage of Java over C is the second program.

for (int x = 1; x <= 100; x++){ System.out.println("Hello World! " + x); }

vs

for (int x = 1; x <= 100; x++){ printf("Hello World! %d! \n", x);

PS: How do you include readable code snippets on HN?


    Prefix four spaces to a line to format code.  
Also, you're missing a right curly brace in the second example.


Perl:

  for (1 .. 100) print "Hello World! $_\n";
Ruby:

  100.times { |i| puts "Hello World #{i}" }


I purposefully phrased my statement to allow for dynamic language like Python - which is what I would probably choose for a starting language. I constructed my comment to also address the same arguments that have popped up in the "MIT switched to Python" discussions.

I've taught intro to Java labs to undergrads, and I did get questions on the scaffolding required. I answered their question, but also told them they don't need to understand that now. I'd rather not have to do that.


I would argue that Scheme fulfills the same purpose we discussed--getting out of the way and letting students focus on algorithms--except it emphasizes expressing those algorithms in a functional style.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: