Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Thursday, August 30, 2007

The Scheming senior

Life has been busy once more, since school started. For some reason, I thought it would be a good idea to take three CS classes (software engineering, programming languages, and cryptography) as well as music theory. Music theory appears to have homework due every class, which sucks, even though it's pretty easy so far. In addition, being a senior now, I have to start worrying about what direction I want my life to go in next year. Of course, being me, I'm still rather indecisive over graduate school versus industry.

Research, to be honest, is so far basically what I made it out to be—boring. It didn't help that I picked a topic that I wasn't particularly interested in, but I'm doing my best to stay interested. Professor Mathur seems to be very passionate about what he does, which helps my motivation a bit. Even though it's not that exciting (calling it flat out boring is also an exaggeration), I guess this is a good experience for me to actually have a mentor that's been in the field for years. Hopefully I can get the motivation to finish this research project and publish a paper at the end of the semester, which would look nice on a resume for grad school. Weekly meetings should boost my motivation, at least a little bit.

Classes are kind of "meh" right now. Software engineering is definitely a lot less exciting than I thought it would be, and kind of wish I had taken something else instead. The project is some sort of grunt work from HP that has to do with finance. It definitely sucks compared to the project binder that we saw, which was a game of some sorts. From what the programming languages book is saying, the class will get more interesting as time goes on, but the current chapters are boring. Cryptography is pretty interesting; it's probably the most interesting thing right now. Music theory hasn't gotten past playing scales, so it's not very exciting. Playing on the keyboards on Friday is kind of fun despite the simplicity, since I haven't played piano in about seven years now.

Perhaps the most interesting thing that has happened lately (at least to me) is the arrival of my latest shipment from Amazon, consisting of:

The Design of Sites is more to get some inspiration for web design, since I clearly suck at it. I guess this is necessary, since the web is the wave of the future. Or whatever. It seems to be very illustrated, but I haven't really looked too carefully at it, yet.

Serenity came out recently, which I couldn't resist buying, even though I already own the original edition. Firefly is one of my favorite series, and extended scenes and more bonus features makes an already awesome science fiction universe even more legen—wait for it—

Last, but certainly not least, I've already gone through two chapters of The Little Schemer. The book takes on a very peculiar format, based purely (at least so far) in Q&A format. They ask questions that you can hopefully answer and give explanations for each answer. For a fairly advanced programmer like me, this is amusing at first, but tiring in some spots. I was hoping for a book that I could read cover to cover, but this doesn't seem to be the book. Not that I'm disappointed with it at all, I just don't feel like reading through levels of recursion that are obvious to me.

This brings about an interesting pedagogical method; Friedman and Felleisen take an approach that depends on the human ability to recognize patterns. It seems like if you ask enough questions, the reader should be able to figure out what a certain function does. I had kind of an advantage of already knowing what some of them did, so playing a game of 20 questions was a bit overkill, but I wonder how this teaching method would apply to a more inexperienced student.

Actually, I already use this method somewhat with students. Whenever a student asks me a question that I deem should be obvious or already known from previous labs/lectures, I bombard them with questions until they figure it out. Unfortunately, this doesn't always work, possible due to a few reasons:

  • The student is lazy. This might be a mean thing to say, but I think it's true. Graduate TAs that run consulting hours complain about students being unable to debug on their own, which I believe should be fairly intuitive. I've even had someone cry, possibly to get me to write the project instead.
  • The student doesn't really understand the language. Compared the Scheme, Java is pretty complex, and some students never really properly learn some language constructs (e.g. the static keyword). This presents a huge problem when you get errors like, "non-static variable referenced in a static context." This is more of a lack of knowledge than reasoning ability, so this is where I throw my hands in the air and tell them to read the textbook.
  • I'm not asking enough questions or I'm asking the wrong questions. This is quite possible; unlike the concepts presented so far in this book, so it's not always possible to ask an exhaustive list of questions to make the student reason through exactly what mess he/she has just made.

Regardless of the potential for failure, I think this could be applied to some specific topics for students to look like. The static keyword is probably a good target to start with. It is not as difficult to make an exhaustive list of questions for the students to "pattern match" through for one single concept, but I guess it's too late to use this kind of method when they're working on projects midway through the semester. Hopefully I can get some spare time to concoct an article for using the static keyword, and get some response from students on how beneficial it was.

Anyway, this has been a very random grouping of topics and I think I've poured out my heart and soul enough for tonight.

Dary.

Thursday, April 05, 2007

Java as a first programming language

A thread on the Something Awful forums came up recently about a high school, second-year computer science/programming course. The author was requesting help to convince his teacher to switch said course from using VB6 to C#. There were a number of suggestions and alternatives given (Java, VB.NET, Python, Scheme), but that's not as relevant to the CS environment at Purdue (thread is here if interested). I got into a couple of discussions about C# and Java, and it brings me back again to imagine what Purdue would be like if we didn't teach Java as a first programming language.

The issue I brought up was an argument against teaching students how to write procedural code in a purely object oriented language. In particular, someone suggested that teaching procedural code in C# was easy, since you could simply add the static keyword to class methods to write non-object oriented code. I argued that teaching the static keyword before telling students what it meant was a particularly bad idea. I've never been a fan of teaching stuff out of order (who is?), but it seems impossible to teach things in order in Java. This is plainly visible by Java's hello world program:

class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

This is incredibly ugly, and C# is guilty of the exact same thing. For beginners, I don't think this is acceptable. Unfortunately, all compiled languages that I know of are guilty of this to some degree; on the other hand, scripting languages can do hello world programs in one line. When you introduce this Java program to a student, here is what new programmers tend to think:

  1. What is public?
  2. What is static?
  3. What is "main"?

The list can continue (what is System, out, println, etc.), but the point is, there are a lot of questions to be answered that can't be answered without covering material that they aren't ready for. In particular, I believe the static keyword is a real killer, even for some people who've programmed before (obviously not in depth). Instead of reiterating everything I said in the thread, I'll just copy and paste like the resourceful (read: lazy) person I am:

I think the static keyword versus other language syntax is slightly different. Why should you have to teach the static keyword first in an object-oriented language? In terms of thinking about objects, static "breaks" the OOP paradigm. One of the C# compiler devs even argues that the static keyword shouldn't exist. Obviously you need some way to differentiate between instance and static methods, but I never really liked to use of the word "static" to do so. Maybe it's just me, but when I hear the word in a general context, I take it to either be in terms of static you see in TVs, or static as in unchanging, the latter of which is due to static/DHCP IPs. Are people really supposed to be able to tell what "static" means, just offhand?

OOP languages like C# and Java are actually backwards in terms of expressing methods and their arguments. If you were to write OOP code in C, the "instance" methods would be the ones with the extra typing (the first parameter being the object type), and the static methods would simply do the opposite. In Python, declaring methods is the exact same way. All instance methods in Python begin with a "self" whereas static methods simply don't have a self. You can also call instance methods with static syntax, which gives some insight into just how OOP methods are actually defined.

As far as learning is concerned, I think Python is better for teaching the difference between static/instance methods (other topics are debatable). I really don't like telling my students, "oh, don't worry about this huge, gigantic header you have to write for your main method--or what a main method actually is. You'll learn that later!" {}, (), [], and <> are introduced in a more appropriate order (though funny enough, I do have students that still don't get the paren), so I don't think it's [as] relevant.

A post from another user probably summarizes very well:

introducing students to computer science through languages which introduce syntax issues long before they introduce computer science concepts is a recipe for failure, and I completely agree. Aside from the utter boneheadedness of an "objects early" or "objects first" approach, you're giving students a gigantic chunk of boilerplate code and not explaining what any of it does. Seriously, just think about it: a student is not going to be thinking in object-oriented terms right off the bat, so how do you explain what this "public class" and "public static void main" business is? The Javaschool answer is "we don't, we just tell them that it's not important and they'll understand it later." This is not an acceptable approach.

From what I've observed, Java is taught at Purdue (and other schools) for a few reasons:

  • Java is the number one language used, at the moment
  • Java is heavily involved in other courses (for Purdue, often data structures and compilers), and not teaching Java would have a severe impact on the curriculum
  • It's a good gateway to other statically typed languages, unlike Python and company, because of syntax similarities

There was, however, a comment by the same user above, regarding Java in computer science programs:

I've been doing a lot of research into computer science education recently (I'm more or less rewriting a computer science curriculum for my college), and there have been numerous studies which show poor computer science retention rates in Java-based computer science programs (equivalent to ACM CS1 core) that have improved substantially when the course syllabus was switched to a simpler language like Python or Scheme which allows students to focus on computer science concepts rather than fighting with language syntax. Pummel them with Java later.

While the idea of teaching a language that isn't statically typed bugs me, maybe it's just my upbringing in C. As far as static methods in classes go, I would certainly agree that Python does a better job of getting the idea across, as said in my quote above. However, I also think Python offers a lot of freedoms that aren't available in C# and Java (as do most scripting languages), which might increase the difficulty of learning statically typed OOP; nevermind the syntax differences between Python and "C-family" languages.

On the other hand, Python's enforced proper block indentation also brings something refreshing to the table. I've seen some extremely bad indention in Java (literally different levels on each line in a block!), and I think Python has taken a good step by enforcing uniform indentation. Unfortunately, we don't see this in most languages, so this is a nice plus to using Python as a learning language.

Unfortunately, I'm still not sure teaching Python as a first language is a good idea. I sure don't like Java (for anything), but then again, I don't know of any languages that I would rather teach students that have advantages that are substantial enough to merit a change in a class syllabus. I don't think functional languages will ever fly here, regardless of how pretty or ugly they look; the idea of CS180 is to prepare students for CS240, which transitions from Java to C. I don't think the Pythonic way of doing things will prepare students for C; it may teach you how to program, but as much as it makes no sense, I'm guessing it would just pass along the problem to the CS240 instructors. And we all know what kind of monster that would awaken.