Which language is better for a hacker newbie?

Posted 23 Jan 2002 at 21:28 UTC by fuzzyping Share This

I'd like to branch out past scripting and try my hands at some C/C++ programming, but I'm not sure which language to try.

I understand that C++ is a superset, so I can just start with it and still have all the functionality of your standard C libraries and such. Besides that, what do you see as the "competitive advantages" to using C++ over C? Granted, I'm probably comparing apples to oranges... C is better if I want to hack on OS's and network stacks, C++ is better for application development. But what if I'm not that static? Are the OO semantics in C++ advantageous enough to make me want to learn this first? This week I want to develop a communications client using ncurses, next week I might want to hack on some kernel drivers.

Suggestions? Warnings?


OO scripting, then C, then C++, posted 23 Jan 2002 at 22:08 UTC by sej » (Master)

I'd say try some object-oriented scripting language or interpreter (i.e. Python, Common Lisp, or Java), then a compiled hardware-friendly language like C, then C++. Jumping to C++ without practicing the intermediate skills of OO and C programming might be frustrating. Every satisfied C++ programmer I've met followed this path.

agree with sej, posted 23 Jan 2002 at 22:56 UTC by sdodji » (Master)

I agree with sej. It is a good thing to start with a langage that stresses on the OO practices. C++ is a very stretch language. What your program looks like at the end depends directly on your ability to be "clean" and rigorous. (that is true for any language actually, but with C++ you must be especially carefull).

Try Java and/or ruby. They are very well designed language with a clean syntax and true object concepts. Then, once you understand the OO concepts and pattern, you can join the C++ arena. I think that understanding these 00 concepts and patterns can help you write cleaner C or Perl code.

Good Hack !!

Perhaps I should elaborate..., posted 23 Jan 2002 at 23:21 UTC by fuzzyping » (Journeyer)

It sounds like I gave the impression I was really interested in OO. Rather, I simply want to choose between C/C++ as my primary interest right now. I understand that OO is a good philosophy to adopt, but my concern right now is "what language is best for the types of projects I want to do?".

First and foremost, I'd like to be able to hack on existing C projects, kernel and driver code, etc., should the opportunity arise (and it well). Next, I expect that I might want to code a few applications, but it's unlikely that these will be anything resembling "commercial" code, so I'm not sure how important it is for me to have the OO framework at my disposal.

Lastly, I really have no interest in today's chic languages (Ruby, Java, Python, etc.). If I need to script something (OO or otherwise), I use perl. The only exception I can see to this is perhaps learning some java while investigating the j2ee projects. I'd simply prefer to stay closer to the hardware level without having to dig in at the assembly level.

**Note: This is for my own personal, non-career, self-fulfillment. I have no drive or desire to program for a living. Rather, I enjoy coding/hacking and giving back to OSS wherever and whenever possible.

I hope this clarifies things a bit. Thanks again!


I think you answered your own question, posted 23 Jan 2002 at 23:39 UTC by davidm » (Master)

From your clarification go with working with "C" if and when you move to applications move on to "C++".

Have fun!

C or Python, posted 23 Jan 2002 at 23:48 UTC by raph » (Master)

I can highly recommend C as a first language. If you're bright and motivated, I also highly recommend K&R over one of those "C for morons in 24 hours" books.

Objects are an incredibly useful and important tool, but they are one among many. I'm not sure why people stress it as being so important for beginning programmers, particularly because the concepts are complex.

The nice thing about learning C is that almost all of the concepts are essential in other programming disciplines. That's certainly not true for C++, where you've got bizzare things like references versus pointers, complex rules for multiple inheritance, and cool interactions between templates, operator overloading, and other stuff.

Writing real programs in C requires mastery of memory allocation discipline, which is especially difficult for beginning programmers. This is, I believe, one of the big reasons why people tend to shy away from C as a beginner language. Just something to keep in mind.

All that said, I can also highly recommend Python as a good beginners language. The fact that it's interpreted makes it a lot easier to work with. It's also nice and clean, with few extraneous features. It's becoming my tool of choice for prototyping and one-off programs, and I'm finding myself really enjoying it. I'm not sure why it isn't more popular as a free software platform.

If you start with Python, you'll find that the language takes care of most memory allocation issues, and can start working with "higher level" data structures such as lists and maps very quickly. You can also do objects, although you're not forced to.

Best of luck, and enjoy!

C, posted 24 Jan 2002 at 00:20 UTC by mslicker » (Journeyer)

If C and C++ are your only considerations, choose C. It's the language of Unix which seem inclined to program, and I am one who belives applications written for a particular system should use the indigenous tools provided by the system. In addititon, C++ provides no signifigant advanage, especially for the greatly added complexity.

In regard to OO. I have found, in general, it only complicates the task of solving a problem. Other's experience seem to differ, in any case it's an unecessary tool for computer programming.

Good luck with your endeavour!

Every joke has some truth in it, posted 24 Jan 2002 at 01:50 UTC by Zaitcev » (Master)

The C++ Inteview

Languages to use for learning, posted 24 Jan 2002 at 06:20 UTC by jameson » (Master)

I've discussed this with a number of people, and most of them seem to believe that Eiffel is one of the best languages to use for learning OO. Note that I have not used this language yet, so I cannot comment on that.
For a different point of view and a very well-defined language, try Haskell; a purely functional language (somewhat similar to Standard ML or Scheme, except for really being purely functional and using call-by-name semantics). I haven't done any large projects with it yet, but it does strike me as an incredibly readable language (i.e. compact code, powerful functions) with features you won't find in most imperative languages.
That being said, if you desire raw performance and want to get close to the hardware (and you don't want to do that on a learning tool like SPIM), C is- IMHO- the way to go. Without understanding C (or a similar language), it's hard to see the point in some of C++' features; while there are supposedly some people who have "mastered" C++ without prior experience in imperative languages, this seems like a risky and potentially frustrating route to me. So my suggestion is this: Use C, and when you start considering passing function pointers as parameters as normal things (and begin to wonder why you can't compile the resulting function statically), or when you realize that this particular thing you've implemented could work much more generically if you could pass a type as a parameter, then you might start looking in to C++. (Yes, C++ also has better support for hierarchical types and for operator overloading, but the former can be emulated easily, whereas the latter rarely matters in practice (except where required by the STL)). That being said, the one really good thing C++ will give you is the STL (Standard Template Library), one of the few successful attempts at generic programming. But, again, you can have that more conveniently in Haskell (and, probably, Eiffel); for C++, you should really try to understand how it works internally, and that'll be hard to do without experience in C (or similar languages).

Note that I still use C instead of C++ for most of the close-to-hardware stuff I do, for two reasons- I have more experience in keeping C code portable than I do with C++ code, and C simply compiles an order of magnitude faster than "real" C++ does. (OK, to be honest, there are two other reasons- I haven't really grown accustomed to the language yet, and I can't bring myself to like its design.)

Also, you should try to avoid languages that were grown rather than designed, like Perl. Perl has incredibly complex semantics, and, while it does have its use in practice, if you use it as one of your first programming languages, you risk slipping into the "let's do it by intuition" kind of mind frame. This may be a problem when trying to use other programming languages.

superset, posted 24 Jan 2002 at 14:27 UTC by stefan » (Master)

I don't think that thinking of C++ as a superset of C is appropriate. C++ programmers do things very differently than C programmers, there are a whole set of different paradigms you can exploit. When you want to learn C, do it. But if you want C++, learn C++, not C.

As a C++ programmer, you certainly will be able to understand C programs, but you won't program the way C programmers do. You don't need to.

And, by the way, another language to consider just to get started with some basics (and with a much less steep learning curve) is python.

C++ for the newbie, C for the kernel hacker, posted 24 Jan 2002 at 15:25 UTC by abraham » (Master)

A good C++ book allows the newbie to be productive long before he has to learn the really hairy stuff inherited from C, like pointers, typecasts and memory allocation. Most of this is nicely encapsulated in the standard library.

However, if you are going to hack an existing C program, like the Linux kernel, you will need to learn all the hairy stuff anyway. And using C++ in the kernel will be frowned upon.

So if you want to start hacking the kernel as soon as possible, start with C. If you can delay the kernel hacking a few years, start with C++.

I don't consider OOP support the major advance of C++ over C, it is not that hard to simulate in C. The major selling point is the efficient large typesafe standard library, that gives you many common datastructures and algorithms for free.

Don't learn a language..., posted 24 Jan 2002 at 15:40 UTC by Darkman » (Apprentice)

I've come to the conclusion that learning a programming language is the biggest hinderence to learning to code. The abilitiy to program in independant of the language that you work in. Therefore worrying about the language that you use is as effective as worrying about which make of car you take a driving test in :- Yes, there are slight difference, and yes, being familier does help, but only in a trivial fashion.

There are, what, 4 programming paradigms [0].

1) Procedural. Best exemplfied by C and Fortran. Best used for well understood problems (from a CS point of view). Hence a lot of Scientific programs are written in this paradigm.

2) Object Oriented. Classic example of Smalltalk, most common is Java, or maybe C++ [1]. Best used when the problem is not well understood at start, or subject to change during development.

3) Functional. Best exemplfied by Lisp. Other favourites are Scheme, Haskell and the ML family. Let you do things that would be conceptually impossible in other languages, such as dynamically generated code, and operating on parse trees. Vastly simplfy some other aspects too.

4) Declerative. Best exemplfied by Prolog. Languages that specifiy what is to be computed, but leave the details to the compiler. Used for things like expert systems, and has applications in data mining. In reality, most real programming crosses these conceptual boundaries. For example, I have done an objected orientated, functional type program in C before [2]. However, knowledge of the different styles is more important than a specific language [3].

With this is mind, I'd reccomend learning C, as pure proceduaral, followed bu Java, as an OO style, then struggle for a bit till Lisp makes some form of sense. At this point, look at other languages, and then you'll be able to tackle most things.

As an aside, I think that the modern thrust for OO is due to the concept of encapsulation. This gives a neat, and straight forward manner of distributing work amoungst a team of programmers, something that is not so natural for a pure procedural language.

[0] I'm not 'in' CompSci, so I've probably missed one or two. [1] C++ is a hybrid language. Very useful, but not, in my opinion, good for learning with. [2] Not to say that it wouldn't have been easier in an other language.[3] From an academic point of view. From a commercial point of view, you get a different opinion.

...and the four are really one., posted 24 Jan 2002 at 16:22 UTC by cmiller » (Master)

Darkman has it right. Languages are cheap, gaudy, and inefficient representations of the inexpressible Single Hacker Language. You don't want to get bogged-down in the workings of a behemoth like C++ until you can speak (or at least grunt) in The Over-Language. It's necessary to study a couple of trees, to get a handle on the properties of the forest, but when a tree requires dendrochronology, cellular biology, and astrology, like the C++-tree does, you should move on to the simpler trees and come back to it later, if ever.

Perl, which you know, is awfully C-ish in a lot of repsects, so try it, but not necessarily first. If you haven't tried it, study some Scheme, first. I'm now of the opinion that all potential coders should learn it, before anything else.

Then, maybe C, in your case. For real newbies, I would recommend it much later.

Then, tcl and Python.

Then, Smalltalk and Java. Learn OO ideas here.

Spend a month or so on each paragraph above.

(If you're in no hurry, you could throw in a bunch of other languages here, too. Try BASIC, just to learn to hate bad programming style; try to build something big. Try Pascal. Haskell. Prolog.)

Then, C++ .

Beware that C++ is big. You'll never learn it all. No, really. At best, you'll grok a subset that is useful, but no one groks it all.

Finally -- don't dismiss "today's chic languages." All languages have something to teach you about The Over-Language.

...except PHP. PHP is has absolutely no worth at all.

Best of luck!

Just dive in., posted 24 Jan 2002 at 18:10 UTC by logic » (Journeyer)

My own programming background is probably pretty normal for a lot of people here; a mix of formal learning and schizophrenic interests.

I learned BASIC (using Applesoft BASIC for the Apple //e), did a bit of work in 6802/68C02 assembly, played a bit with DOS batch scripting, then started taking formal computer science focusing on Pascal (final year of high school and first year University, using TurboPascal for DOS and Windows, and LightningSpeed Pascal for the Mac). Following on that, I kept up learning on my own, with VMS DCL scripting, then LPC (an interpreted C derivative offering an interesting spin on object-oriented design) for use in the online games I'd managed to addict myself to. That lead to C, since I wanted to play with the LPC interpreter, which was followed (conveniently enough) by formal classroom training to fill in some of the gaps, along with a class focused on TCL. Out in the workforce, I made myself learn bourne shell (sh, ksh, bash), awk/sed/regular expressions, Perl, and Python.

After Python, I decided that, really, they're all the same. We've coined a certain set of features, and most modern languages implement most of them. They all have their strengths and weaknesses, usually defined by the availability of libraries or modules that can speed up development. So, use what you find most effective and enjoyable. Personally, my new favorite is probably Scheme, but I still find it hard to resist spending a little time and learning new languages as they come along (Java, Ruby, C#, etc) in the hope that maybe one of them will introduce something new.

This was all really a long-winded way of saying, "It doesn't matter, if you really enjoy programming." Eventually, you'll probably come into contact with and make use of a pretty wide spectrum of languages. C will give you a good introduction to programming to make the hardware's life easier, and with a more limited set of major topics, might be easier to tackle at first. An OO language might make for a good follow-on (C++ would make a reasonable choice, since the learning curve of the basic language constructs wouldn't be there, but any would do) to fill in a few gaps in the "what is possible?" arena. Following on that, a functional language like Scheme would fill in more gaps.

But whatever you do, don't take our word for it. Just dive in.

whatever works, posted 24 Jan 2002 at 19:52 UTC by rjp » (Journeyer)

my sequence: pascal (for one quarter, never touched it again), then c/sh/csh/ksh concurrently, then c++, then a survey of list-based and declarative languages, then java/perl concurrently.

imo, before looking at a single line of code, people should learn basic programming constructs first: looping, branching, iterative vs. recursive, then move on to records/structs/classes, functions/modules, etc, all explained and practiced with in natural language (come to think of it, pascal and basic are pretty darn close to that). then, the first time someone sees some non-intuitive c or perl or java or c++ construct, it won't throw them off.

but ultimately, however you get there, there you are.

Pliant as a better C extension than C++, posted 25 Jan 2002 at 11:29 UTC by pliant » (Master)

Here is the article about Pliant comparing it with various other language: Pliant language

Not C, posted 25 Jan 2002 at 12:22 UTC by nether » (Journeyer)

Raph, come on:

The nice thing about learning C is that almost all of the concepts are essential in other programming disciplines.

So do you think that

  • pointer arithmetic
  • casts
  • prototypes and forward declarations
  • headers
  • numeric characters
  • NUL-terminated strings
  • uninitialized variables

are all universally essential?

Writing real programs in C requires mastery of memory allocation discipline, which is especially difficult for beginning programmers.

Moreover, the baroque details of memory management are far from the most important things for a beginning programmer to learn. Learning proper abstraction and program organization is much more important, and having to deal with malloc and sizeof and free diverts you from those. Not to mention obscure problems like accessing free():d data, which may or may not cause a segfault, etc...

C is a great language for low-level stuff (and with C99 it's even possible to write relatively portable low-level code without preprocessing gimmicks), but I definitely wouldn't recommend it as a first language.

Python or Lisp or Scheme ... or may be C, posted 25 Jan 2002 at 19:17 UTC by rkrishnan » (Journeyer)

As raph says, do not use "How to become a C dummy in 24 hours"... I have an electrical engineering background, but have not taken any course in CS so far, but I had been programming for last few years. But there is a lot of importance in understanding some key concepts in CS theory. I have started working through the SICP (or the wizard book, as it is called). Also Brown University has a lot of course handouts on the web (CS173, if I remember the course number correct) which will also be very useful.

Emacs Lisp is also a good starting point, but experts say that it is not a good Lisp to start with. Scheme is small, the R4RS manual is only afew pages thick. Also Scheme is cleanly designed, so is a great language to start.

Also people say that Python is good as a starting language.. now a days I see "Python" in a lot of places and have been convinced by a lot of people that it is a good language to start and use for writing some serious non-academic programs.

Systems Programming, posted 25 Jan 2002 at 22:52 UTC by nymia » (Master)

It looks like your interest is Systems Programming[ 1 , 2 ]. There are several languages that might be of interest. PL/1 is cool if you have access to Big Irons, compilers like C/C++ and Assembly are there for Unix and other similar environments. If syntax is a problem, there are Algol- like languages that might fit as well, Pascal or Modula are good candidates though. There are a lot of interpreters like Java, Basic, C#, Python, Ruby, Bash, Korn, sed, awk and Perl that are also "must- haves."

Regarding OO, I think it would pose a problem since it is hard to figure out which one (OO or procedural method) is valid from the start of a project.

Regarding which is better: C++ or C? It depends on how you would want to lay out the memory, or how jumps or calls would occur. If you're at that level sensitivity, then C++ and C are two worlds apart. For example, C++ mangle its symbols, while C doesn't. On the other hand, if memory layout or name mangling is not an issue, then C++ is the way to go.

IMO, I strongly recommend Assembly, C would not be that hard coming from that direction though. There are programs like nasm or gas that are good assemblers for beginners to munch on.

Perhaps getting some Lex and YACC skills might get you building interesting never-before-seen interpreters.

Definitely C, posted 29 Jan 2002 at 04:57 UTC by ianb » (Journeyer)

If it's a choice between C and C++, then definitely you should start with C. Everything you learn in C you have to learn in C++, and it's not a bad order to learn things in -- maybe not the best order, but not bad.

You can learn most of C fairly easily. And you should learn most of C. C++ you are unlikely to learn completely, and that's fine.

C books, posted 30 Jan 2002 at 00:19 UTC by alexh » (Apprentice)

If you want to learn C, get the K & R book. That's the book titled 'The C Programming Language' by Kernighan and Ritchie. I've got the first edition, I think it's only 270 pages. And it covers everything you need to know. They're the guys who designed the language, so they should know!

I especially like it because it's all Unix oriented. The examples are things like implementations of getc and fopen, which is acutally useful.

Adive: Don't take advice from people who only seem to know C, posted 30 Jan 2002 at 21:33 UTC by ralsina » (Master)

In this thread I see things like "all you need to learn for C you also need to learn for C++".

That is a classical example of someone who knows C and MAYBE he thinks he knows C++ because he can compile his code after he changes the suffix to .cpp.

Real stuff:

You don't even need to know pointers in C++ to write useful code. You need them in C for anything nontrivial.

On C++ you have the stdlib that contains a whole lot of garbage that every C programmer ends rewriting (containers for instance). This has improved slightly with glib, but it is still not there.

If you need OO in C, you end with verbose hacks because you are fighting the language. Fighting the tool you use is usually quite annoying. You may get used to it in the end, though. However, often people don't even know how hard they are making their own lifes because they just don't know any better.

You can learn a very limited subset of C++ and write decent useful code. The subset of C++ you need to write useful code is not a whole lot larger than C. And it is way less error prone!

In any case, choice of language is subordinated to task. What do you want to do?

Until you have a really clear answer to that question, you can not have a good answer to What language should I use?

And when you know what you want to do, the choice of language is usually pretty clear.

For example: if you want to learn to code, it is obvious you should not choose C++ or C. Try python.

If you want to hack the linux kernel, you are forced to C.

If you want to write an application, it is arguable, although let me assure you, C is probably the hardest path you can follow, barring FORTRAN or somesuch ;-)

Re: Language Doesn't Matter, posted 2 Feb 2002 at 12:27 UTC by nerdgir1 » (Journeyer)

I agree with the previous statements that basically support the statement that the language itself is irrelevant. The most important thing is to set reasonable goals for yourself and stick with it.

Learn how to program... or more importantly learn how you learn cuz languages, programming paradigms and api's change.

Or put simply - There is no spoon.... hee hee...

Re: Language Doesn't Matter, posted 2 Feb 2002 at 12:45 UTC by nerdgir1 » (Journeyer)

I agree with the previous statements that basically support the statement that the language itself is irrelevant. The most important thing is to set reasonable goals for yourself and stick with it.

Learn how to program... or more importantly learn how you learn cuz languages, programming paradigms and api's change.

Or put simply - There is no spoon.... hee hee...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!

Share this page