Best teaching questions in October 2010

Where can I find a C99 front end with good error message for students

16 votes

I'm teaching a course in which students get their first experience programming in C. We're using gcc on Linux and (for beginning students) the user experience is terrible. I'm looking for a C front end that will do one or more of the following:

  1. If it cannot find a .h file, announce the fact and shut up. Don't spray screenfuls of garbage so that the information about the missing .h file is lost.

  2. If an known name appears in a type-like position, it should trigger a sane, sensible error message. For example, the source code

    typedef struct Queue {
        Array_T elements;
        int first, last, length;
    } Queue;
    

    Should trigger a message like

    Line 2: I saw `Array_T` used as a type, but it 
    has never been declared as a type.
    

    In this same situation, or especially in function prototypes, gcc produces incomprehensible gobbledegook.

  3. In an ideal world, the tool would also detect attempts to link libraries out of dependency order. After all, we know how to do topological sort now.

There is no requirement that the tool be able to compile any code. I am looking only for a way to get better error messages. The only hard constraint is that it has to be able to run on 64-bit Red Hat Enterprise Linux, because that's our teaching platform. Also, it has to understand C99.

I'm aware of research front ends like CIL and an older effort at AT&T, but I don't know how they are on error messages. Similar comments on the EDG front end, which is free for educational use. I'm also aware that Gimpel Software may have some commercial offerings that might fit the bill. I don't know what budget we have, but I'm willing to go to my department head and ask for money.

I ask the collective wisdom of StackOverflow: what C99 front ends are available which issue error messages that beginners can understand?

Clang generates far better error messages. Get it and try compiling

#include <bogus.h>

It gives

aho.c:1:10: fatal error: 'bogus.h' file not found
#include <bogus.h>
         ^
1 error generated.

It even uses colors on ANSI terminals.

Try

typedef struct Queue {
    Array_T elements;
    int first, last, length;
} Queue;

which gives

aho.c:2:5: error: unknown type name 'Array_T'
    Array_T elements;
    ^
1 error generated.

These features are not just good for beginners. It's good for every programmer!

First programming language to be taught - C or Python?

11 votes

I know that there is a long debate regarding this matter. I also understand that this is strictly not a programming question. But I am asking here as this platform contains wide range of experts from different realms.

When we got admitted in a Computer Science and Engineering(CSE) course in university, we were first taught C. The course was actually structured programming language but we used C as the language. And on next semester we were taught C++ and Java as OOP. Recently I have heard that the department is going to introduce Python as the first language. I strongly oppose the idea for the following reasons:

  1. Python is a super high language. In the first course the students should become familiar with the basics of programming concepts like data type, pointer, by value or by reference etc. You can write lots of things in Python without understanding these in details.

  2. Python has a wide range of build in data structures and library. In first language students should become familiar with basic algorithms like sorting or searching. I know there is sorting library in C too, but that is not as widely used as Python's sorting methods.

  3. Python is OOP. How can you teach someone OOP when (s)he does not have the basic knowledge of structured programming. If Python is the first language, then they might not differ OOP with non-OOP concepts.

  4. Memory is crucial. If you allocate, then you need to release the memory. These concepts are not necessary with a language with garbage collector.

So what is your opinion? What do you prefer as the first teaching language?

Please don't start a flamewar or something similar. Whatever you suggests, please explain why you think so. And also please keep in mind that the course is for university level. It's not for kids and so trying to make things simple is not much helpful.

And also I know that Python is a great language. I am personally a fan of it. But the question is whether Python should be first teaching language instead of C.

Thanks in advance.

EDIT :

  1. When I asked this, I was not aware about programmers.stackexchange.com. It can be moved there if that is better.

  2. The question contains my opinion. That does not mean I don't wanna hear others. In fact that is exactly what I want. Please don't get me wrong. I am not designing the curriculum. So my opinion has no effect on it. The thing is I think this and this, and I want to hear what others think.

  3. I am well aware that this is not a question in that sense. My first para tells that.

Bottom-up learning is often considered the "better" way to learn. Start from first principles and make your way up to more advanced ideas. The problem with this approach is that much of what we humans learn in life doesn't follow that model at all. Children, in fact, are the fastest learners and they do so by pattern-matching, extrapolation, interpolation, etc., all of which would be thoroughly frowned upon by anyone promoting the classical bottom up system. And yet somehow they run rings around adults in learning, say, the language in a new country, not by reading the bottom-up text books faster than the grown-ups, but by talking to other kids.

I don't know whether Python is the best language to use, but I do believe that any language that gets people writing code and solving interesting problems quickly can't be too bad a choice.