Discover and share the best of the web!
Learn more about Digg by taking the tour.
15 Exercises for Learning a new Programming Language
jobsnake.com — Prashant N Mhatre has a working knowledge of several programming languages but job demands to learn a new language frequently in a short time. Prashant shares 15 exercises to master languages quickly.
- 1400 diggs
- digg it
- Vladek, on 10/12/2007, -95/+10These exercises are text-based, console, command-line based. Nothing about GUI's, which is extremely important these days (think Java, or .NET).
- interiot, on 10/29/2007, -12/+73You started programming with VB, didn't you?
- klang, on 10/29/2007, -3/+76NO!
Learning a programming language has nothing to do with learning a GUI.
GUIs change all the time, while the command line, ascii and languages themselves remain more constant. - RocketMike, on 10/12/2007, -4/+37Klang is spot-on.
GUI's are just another interface to a program; they're not part of the actual programming guts.
You don't need exercises to "practice" making GUIs - that's not programming. - Takteek, on 10/12/2007, -24/+27I agree with klang and RocketMike, but what is this "You started programming with VB, didn't you?"
Why do programmers and computer people feel the need to put down anything that is easier to use?
Oh no! Someone with less knowledge than me can do the same job as me in half the time! They're obviously using an inferior programming tool. - AhmedB, on 10/12/2007, -5/+14Depends on the application, if it's a quick and dirty application with no real focus on performance and pushing it to the limit or some form of rapid prototyping, then VB or .Net can do it, but if you want to optimize your code to the last cycle then it's C/Assembly combination most probably (and yes in 2006 some applications or major parts of them are still 'hand coded' in assembly).
- theevilmonkey, on 10/12/2007, -4/+16@takteek: Come one dude, his comment refers to the intrinsically gui-based nature of VB.
Besides, whilst VB is an appropriate tool in certain circumstances, everyone likes a bit of friendly VB bashing now and then, cheer up :)
The parent complaining about ignoring gui stuff when learning a new language seems odd to me though, you cant learn to use gui toolkits if you don't understand the syntax and basic language features. Terminal all the way for learning new languages, then gui. Or a web framework for that language. - unidentified, on 10/12/2007, -2/+10@theevilmonkey
Damn straight! What other language could give him that impression? We aren't just bashing visual basic by asking if that's what he programs with. It's actually very logical, as stated by evilmonkey that's the way visual basic works. The guy probably made a button in VB that displays a picture before dropping out of high school, and now has the impression that programming involves drawing buttons that link to images and pre-written applications that you simply fill in the blanks for.
You can make some sweet games in VB, it's become a very powerfull language, but unless you really get into it and actually create something worth while, it's just going to give you the wrong idea. Of course you could never create an operating system in VB, and it does teach some bad programming habbits, but you would be hard pressed to find a C programmer (windows based) who doesn't know some VB. - sbrown123, on 10/12/2007, -6/+2@unidentified -
I don't know if you would be hard pressed to find a C programmer who doesn't know VB. I don't know VB. But I will admit to toying with QBasic at one point. We all have to start somewhere. And I have noticed that those people who always say "start with C" are those who learned programming in college. Those of us who learned programming before receiving formal education in it are also more likely to know simpler languages like VB (or QBasic). And from my experience, those who learn these simpler languages first usually have a huge advantage over those who started with harder ones when it comes to doing programming as a career. So bashing poor highschool VB programmers is probably bad form. - interiot, on 10/12/2007, -1/+1@sbrown123: I did QBasic -> C -> VB -> (college) -> Java -> ..., so it's okay if I said "you started with VB", right? :)
VB just gives people a bad first impression... like that there's no main event loop, or in terms of chicken-or-the-egg, that GUIs come first, and then somehow your code magically runs... and that GUIs are almost never dynamic... windows just magically get initialized all at once. (though I suppose Perl associative arrays make people think hashes are limitless in size and hash functions are something only cryptographers use, and SQL makes people think that B-trees are always fast and easy to access)
@Takteek: I violated WP:NPA, shame on me.
@RocketMike: System APIs *can* be important to a language... I'll avoid programming languages that don't a decent set of string tools if I can. And one of the most positive things I've heard about Java, even by detractors, is that it has a well-developed and consistent set of standard APIs. That said, many people still consider APIs (including GUI) to be frosting on the cake. - mGee, on 10/12/2007, -9/+1dipsh*t
- StealthTomato, on 10/12/2007, -6/+3I'm 16, and starting learning programming when I was 10, beginning with QBasic. I'll admit, it's not very useful for practical applications, but it's good for learning the concepts of syntax and other such nonsense. Then, I jumped to VB. This was good, as it helped me to learn the basics of object-oriented design.
Nowadays, I use primarily Java and other C derivatives for apps and PHP/MySQL for web design.
VB has merit as a "learning language," but C derivatives allow greater control over the machine. It's low-level languages vs. a high-level language. - YukiCuss, on 10/12/2007, -2/+1@StealthTomato
I like your point of view. I started with QBasic when I was young, and moved onto VisualBasic, but now I see myself as a competent C++ programmer. What's wrong with starting out with something simple? Stepping stones are key. - dassouki, on 10/12/2007, -4/+3I know Java, C++, C#, VB.net, VB (yest they're different) .. i got my own development company. I'll tell you when time is worth money, I'd rather program with C# or VB.net. i don't like to write 45 extra classes for a small built in functionality. I use java if I'm programming for Linux.
@GUI NON-FANS
GUI is important for all of you college students, GUI to the client is the most important feature. and the ease of usability is all about how your program sells. no one cares on how nice and organized and optimized your code is. if the client doesn't get his requested features efficiently and he doesn't get them in a nice orderly fashioned, he won't like your product. if GUI is not important. then check out itunes and compare it to wmp i mean wimp.
just out of curiosity, how many programmers on here actually worked with languages they learned from college ? - strangewill, on 10/12/2007, -2/+0Pretty much as said a couple posts above mine, I started in VB, now I can do some PHP, .NET, Javascript, C#, dabbled in Java...
This article makes perfect sense, GUIs are different, but the coding behind is always the same, learn how to make loops, deal with errors, get user input... How could this NOT make sense? - tony23, on 10/12/2007, -1/+4Learn to code in Whitespace - everything else will be easy, then:
http://compsoc.dur.ac.uk/whitespace/ - tylerni7, on 10/12/2007, -0/+5I'm 15 and know Perl, PHP, C, ActionScript, Basic, Python, and VB. See younger people than you can brag too. Now really GUIs are perhaps the least important part of a program. That's like saying (although sadly it's been said on digg before) that a computer has to have graphics. When you are pushing for performance, graphics make things slower. A real language should have the option of using a GUI or not. And also, stuff takes a lot longer in VB than a lot of other languages. As great as you think VB is, it really isn't that powerful. And also, I'd say start learning to program with Python, because you learn a lot of important things, it's easy, and it will be useful later on in life (although VB can too I suppose)
- klang, on 10/12/2007, -1/+4tylerni7,
"I'm 15 and know Perl,.."
For a 15 year old, you certainly have caught what programming is about; ..1) selecting the right tool for the job. 2) making sure, that you have as many tools to select from as possible.
Keep it up, but do something else with your time as well; take a run, mountain climb, bungy jump .. whatever .. it clears the mind when you are stuck. - greyfade, on 10/12/2007, -0/+1i'm rather proud to say i got my start on CB/M BASIC before moving up to 6502 assembler, QBASIC, C, VB3 (as opposed to today's monstrosity), C++, and now nearly a dozen interpreted languages, including Perl, Python, Ruby, REBOL, and others.
get a Commodore 64, you wusses, and learn to hack it. :D (assembler does the mind good!) - webtweakers, on 10/12/2007, -0/+0@greyfade: Yes, I experienced C64 Basic and Assembly definetely as a good start: it will teach you to write optimized code, 'cos the limitations of the machine are quite tight.
I don't see how the exercices in the article are gonna help much. Sure, you'll learn some basics, but - depending on the language - it won't get you much further than like 1% of what the language has to offer. The writer does give some good tips though: reference cards (or anything simular) are a must; start off with a simple 'Hello World'. Trying to grasp the structure a programming language opposes is the hardest part, imho. Java and C enforces you to work 100% object oriented. PHP doesn't enforce anything.
Try to get a hang of the language syntax and data types. Experiment with examples available on the net.
(oh, and I won't even start summing up all the languages I've learned in the last 20 years - sigh :) )
- fkuall, on 10/12/2007, -1/+4neat idea, i'd never thought of doing that.
good article, nice short read. i can see how it could really make learning a language easier. - OrangeTide, on 10/12/2007, -5/+8goo-what? never heard of them. J2EE has little to do with GUI programming.
before you do anything you need to go onto a forum or chat room and demand that people teach you and debug your programs for you. That's an excellent way to learn a new language.- rushiku, on 10/12/2007, -1/+2"i am needing a code for 2 control enterprise financial system please u send me hurry its urgent!!!!!!!!"
Yeah, I know that guy.
- rushiku, on 10/12/2007, -1/+2"i am needing a code for 2 control enterprise financial system please u send me hurry its urgent!!!!!!!!"
- cheerio, on 10/12/2007, -6/+6Once you learn a strong typed language such as C, it is very easy to move about diffrent languages. I find it easy to just read some code that does something very similar to another program you have written in your language of choice. From this you can easily pick up programming structure, declartion, etc. Also a very big plus is getting a IDE that supports code completion, this way you dont have to actually memorize every function in each programming language. You will notice that function naming conventions in most languages are the same. Just my 2 cents.
- AlanLivingston, on 10/12/2007, -8/+4I wouldn't call C a strongly typed language. C++ perhaps.
- klang, on 10/12/2007, -2/+6I don't know about C++, but I don't think it's more strongly typed than C..
Java is strongly typed. The compiler doesn't let you cast to a random type. - interiot, on 10/12/2007, -6/+1@klang: C's (void*) vs. C++'s templates?
- Eeqmcsq, on 10/12/2007, -1/+1I don't use C very much, but from what I remember, C++ is more strongly typed than C. I remember dealing with a bug in a C source code that the compiler didn't issue an error or warning about, but in C++, the same piece of code would have generated an error. I think it had something to do with pointer types.
- dannywoodz, on 10/12/2007, -2/+6C is not strongly typed: it is weakly typed. Strong typing is where the object that you're referring to knows what type it is. In C, you cannot ask whatever's on the end of a void* what type it is: you just have to have some way of knowing. It is, however, statically typed: the compiler knows about variable types and will tell you about operations that are inappropriate for the declared types. The opposite of static typing is dynamic typing, typically seen in languages like Smalltalk, Lisp, Ruby, Python, etc. Here, the variables are not typed, but every object knows what operations it's allowed to perform at runtime.
- ilitirit, on 10/12/2007, -2/+2@"a strong typed language such as C"
@"I don't know about C++, but I don't think it's more strongly typed than C.."
Wtf. C++ has better type-safety than C, but neither are really strongly typed. - mikaelc, on 10/12/2007, -1/+1The concept of "Strongly typed" languages is not an objective measure - see e.g. http://en.wikipedia.org/wiki/Strong_typing. Personally, I see "strongly typed" as something connected to how many errors the compiler will catch during compilation instead of at run-time. (I would call C++ strongly typed)
DannyWoods: I disagree that "strongly typed" is equal to whether you can determine the type of an object at run-time. This would be 'reflection' (which actually is supported in C++ through RTTI).
As already pointed out, C++ is certainly statically typed, and has better type-safety than C - it has a 'safe casting' operator ('dynamic_cast') which checks for types at runtime. - dannywoodz, on 10/12/2007, -1/+0@mikaelc: I didn't mean to imply that strong typing was some form of reflection: the point is that the actual *thing* being pointed at knows whether or not a particular operation is applicable to it, typically at runtime. There's no need for a strongly typed language to make this information available to the programmer to make use of, but the best ones (IMHO) do. In every case I've come across, the benefits of strong typing are realised at runtime, not compile time, although the line is blurred between the two in the likes of Smalltalk and Lisp. Static typing enables the kind of compile-time analysis that will tell you whether or not your code will run. Type inference can do largely the same thing for dynamic languages, although every scheme I've seen works on a probability that the receiver of a particular message will actually be of a given type when the message is sent.
Getting as much information 'up front' to get compile time warnings typically involves giving the compiler more information about your system (i.e. having explicit types), but whether or not that is a good thing is an almost religious debate that I won't spark off here... ;-) - N432SEAN, on 10/12/2007, -1/+2@"Once you learn a strong typed language such as C, it is very easy to move about diffrent languages."
Ever try Prolog?
Didn't think so. - dailo10, on 10/12/2007, -0/+0I recently read Bruce Eckel's well-written piece entitled "Strong Typing vs. Strong Testing". Good stuff... I digg it.
http://www.mindview.net/WebLog/log-0025
- lava, on 10/12/2007, -16/+5once you're set with java you're set for most things. The only bitch is PHP. ***** dollar signs everywhere. God help you if you have to learn LISP. ***** parentheses everywhere.
- interiot, on 10/12/2007, -2/+4Tcl, forth, make, and cmd.exe all have semi-obscure syntax that isn't immediately apparent. And if you don't have experience with functional languages, you have more than to learn than parens when trying Lisp.
- klang, on 10/12/2007, -2/+5First of all .. $foo is a legal variable name in Java.
Second of all .. php is more or less an untyped language whereas Java is strongly typed.
Third .. Lisp is a totally different beast as indicated above, it is a totally different way of thinking than OO or Imperative thinking..
- boredzo, on 10/12/2007, -3/+8R.I.P. server.
- zzleeper, on 10/12/2007, -3/+3anyone got a mirror working?
- RocketMike, on 10/12/2007, -3/+3Odd, http://www.duggmirror.com/programming/15_Exercises_for_Learning_a_new_Programming_Language/ doesn't seem to work.
- antdude, on 10/12/2007, -2/+1Not here. Coral Cache, Dugg Mirror, and Google Cache failed. :(
- theob, on 10/12/2007, -5/+0it doesn't work for me either ... :(
- shm1, on 10/12/2007, -1/+25Here's another copy of the same article:
http://smartprogrammer.blogspot.com/2006/04/15-exercises-for-learning-new.html- antdude, on 10/12/2007, -3/+3Thank you. :)
- zephc, on 10/12/2007, -1/+9his points can be distilled to one point: practice, practice, practice.
- AhmedB, on 10/12/2007, -1/+8Developers, Developers, Deverlopers, Developers!
Developers, Developers, Deverlopers, Developers!
Sorry man, didn't mean it but "practice, practice, practice" sounded close to it :)
- AhmedB, on 10/12/2007, -1/+8Developers, Developers, Deverlopers, Developers!
- ridiculoufish, on 10/12/2007, -4/+2"Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc."
In other words, is the language C++? His choice of examples doesn't give the impression that he indeed has a "working knowledge of a bunch of programming languages."- Eeqmcsq, on 10/12/2007, -2/+2Maybe C++ is his strongest language, and he uses that as his basis for learning other languages.
He does mention namespace/package/module, so it sounds like he's been through Java, and whatever language uses "module". - duality, on 10/12/2007, -1/+2"In other words, is the language C ?"
True, C is the only language I know of that has all of those features, but none of them are completely unique to C .
* Operator overloading is a feature in Ada.
* Virtual functions are a feature in C#.
* References are a feature in Java.
* Pointers are a feature in Assembly language (for practically any processor).
After reading the copy of the article posted by shm1, I think that is a pretty good exercise. However, I would also add to it that you should learn how macros/pragmas/preprocessor directives work in your new language too. Aside from the major paradigms like object-oriented, functional, imperative, et al, these are the things that make the most difference between one language and another. Java is the only language I can immediately think of that has no such system implemented in it.
(Oh, and if you have a long list of languages that you're trying to learn, insert Prolog third from the top unless you already know it, or it's higher than that already, or time doesn't permit it, etc.) - AhmedB, on 10/12/2007, -1/+5What about defining/declaring data structures no matter how complex they are, I remember a sentence from one of the books (or maybe it was a professor) who said: No matter how complex your algorithm is, a suitable data structure can make it very trivial, on the other hand an unsuitable data structure can make it a living nightmare.
- mikaelc, on 10/12/2007, -1/+2C# has all of the above features (for pointers it is necessary to use unsafe mode.)
- Eeqmcsq, on 10/12/2007, -2/+2Maybe C++ is his strongest language, and he uses that as his basis for learning other languages.
- dharm, on 10/12/2007, -7/+4porgramming from one language to another is trivial. The only thing complicated would be getting use to syntax. You apply the same logic and principles from the old language to the new one. You will be setting/getting, and calling functions. And then whatever benefits the language provides is just bonus reading material...
same thing can be applied to scripting languages.
its trivial...- Scarblac, on 10/12/2007, -1/+4Not really, the language does make a difference. Trivially so if the languages are completely different (like Haskell has really no similarity at all to Java), but even in so-called "mainstream OO" languages the presence of different language features means you use different patterns.
For instance, languages like Ruby and Python are big on "duck-typing": a sort of loose definition of typing, an argument to a function doesn't have to be a specific class, but rather loosely implement some interface. In Python you can do "print >> ob, string", and it will work as long as ob has a function named write(), that doesn't cast an exception if you pass it a string as an argument - no other requirements.
That's rather different from languages like Java, where an object needs to implement all of a specific interface with a specific name.
In Perl you can re-bless an object so that it's an instance of another class, at runtime...
Another big difference between languages is in their standard libraries, things that are trivial in language A because it's part of the language or part of the standard library and therefore are a very common idiom, are almost never used in language B because there that method needs some external library, while there's another way to do it that IS part of the language.
It all means that in different languages, the best design patterns to use in similar situations are often different. - Grimboy, on 10/12/2007, -2/+1The only thing complicated would be getting use to syntax.
Which is why some people go all weird about lisp's brackets and python's whitespace. Some people just won't but in the time to get over the initial pain and disoriantation. - starsky51, on 10/12/2007, -0/+4@Grimboy did you not read Scarblac's comment?
Different languages are designed to solve different types of problems. Getting used to the syntax might help you when you're writing a 'hello world' program but understanding the problem and the design implications is more important than knowing where to stick your curly brackets. - pauldonnelly, on 10/12/2007, -1/+2@Grimboy
Lisp is different in more than syntax, you know. - burke, on 10/12/2007, -2/+1Way back when, there were two main (popular) programming language styles: 1) Algol-based (see C, Java, PHP, Python, etc., etc.); and 2) Lisp and derivatives (see Emacs Lisp, Common Lisp, AutoLisp, Scheme). The Algol variety won out because they're more useful as general purpose languages (generally). Lisp was reduced to the sidelines; it's far too different for the majority of people to learn.
- klang, on 10/12/2007, -0/+1Here is a list of 264 different implementations of the popular ""Hello World" program:
http://www.roesler-ac.de/wolfram/hello.htm
Yes .. even the language ***** is "just syntax" ..
++++++++++[->+++++++>++++++++++>+++++++++++>
+++++++++++>++++>+++>+++++++++>+++++++++++>+
+++++++++>++++++.
..might have to exchange the "just" for dificult.. - webtweakers, on 10/12/2007, -1/+0@dharm: I agree. In the end, programming is nothing more then moving memory: a = b. Learning a new language is finding out how to do that best in your chosen language.
- Scarblac, on 10/12/2007, -1/+4Not really, the language does make a difference. Trivially so if the languages are completely different (like Haskell has really no similarity at all to Java), but even in so-called "mainstream OO" languages the presence of different language features means you use different patterns.
- noouch, on 10/12/2007, -6/+4Hello world.
- dwhitbeck, on 10/12/2007, -1/+1I liked Delphi before .net. Pascal in this form is more than a "teaching language." It has a logical syntax, strong typing, inline assembly and very rapid compilation. For mathematical problems and recursive solutions, Clean is a very interesting language. VB was always a load of crap, foisted on programmers by Bill Gates who thinks he invented Basic.
- klang, on 10/12/2007, -1/+1Different tools for different jobs.
list, functional, imperative or object oriented languages can all be used to get the job done .. if you are sufficiently skilled...
If you are forced to use a specific tool, looking at the 15 excercises will get you started.
What TFA basically says is: look for things you know in the language you don't.
The corollay of course is: Given a choice; choose the language you are best at! - Lutja, on 10/12/2007, -1/+1I still love delphi for asp.net - Its better in every possible way than the *.asp.net implementations in visual studio.
- klang, on 10/12/2007, -1/+1Different tools for different jobs.
- Leion, on 10/12/2007, -2/+1I do not know GUI programming. I only know C/C and Java. Not all programs need nice GUI. Having nice GUI do not equate to good programs.
- Lutja, on 10/12/2007, -4/+1...but it does equate to the compiler that you are using having good developers
- dr-steve, on 10/12/2007, -0/+15Been programming for 30+ years, have learned far too many dialects and languages.
To those commenting on GUI learning: that's the author's first comment ("learn the IDE")! By the time you finish the exercises, you will be well familiar with the IDE as well as the language syntax.
The article has a good set of exercises for learning the basic syntax. And nothing on learning what/why a particular language is an important dialect, what additional "recent trends" it incorporates into its core.
As far as I'm concerned, there are around three core languages: LISP, APL, and the rest. (I'm an avid and long-term LISP programmer, I've written around 4 LISP interpreters -- if you REALLY want to learn the nuances of a language, write a compiler/interpreter for a fundamentally different language. Write LISP in C/Java/VB/Fortran, or write Fortran in LISP.) (BTW, if you want to learn how to write extraordinary SQL queries, use everything you have learned in LISP -- applicative functions, mapping, filters, it is the same as highly nested SELECT, JOIN, etc. with appropriate GROUP/WHERE clauses). So begins the Language-As-A-Religion war. But it is fairly easy to move from PERL to C++; you're in a similar paradigm (sequencing, function, data abstraction). APL and LISP are a much longer leap.
Anyway, look at the list and you can eliminate at least half of the entries. You have
1. Basic I/O
2. Looping and alternation
3. Built-in functions
4. Output formatting and File I/O
5. System/information ("time/date")
6. String (three tasks for strings?!?!)
7. Homogeneous collections (arrays) (no structures?)
8. First-order operations (pointers, overloading, etc.)
Sounds kinda like the Intro to CS books I used to use when I taught!
-Steve- sensibledriver, on 10/12/2007, -2/+1^ Well said.
- Teh_Psyren, on 10/12/2007, -13/+1I refuse to take advice from a paki (lowercase for a reason).
- sensibledriver, on 10/12/2007, -2/+4^ Asshat.
- Psylabs, on 10/12/2007, -5/+2maybe this guy should English first.
@Teh psyren... who's a paki?- appy77, on 10/12/2007, -1/+1cute, funny. those who dont get the message may bury this comment. ha!
- mhatrep, on 10/12/2007, -0/+1@dr-steve
>> But it is fairly easy to move from PERL to C++;
I don't agree. Perl needs a different mindset. It's easy to move from sed/awk/shell programming to Perl.
C++ by definition doesn't support regular expressions so you need an additinal regex package.
As far as OO features in Perl concerned, I always feel they don't blend well into the language by design. - lobrien, on 10/12/2007, -0/+0I propose a set of exercises that are closer to what you'd expect of a person claiming to "know" a language well enough to get hired: http://www.knowing.net/PermaLink,guid,f3b9ba36-848e-43f8-9caa-232ec216192d.aspx
- bestechgear, on 10/12/2007, -0/+0Is there a summary online comparing the uses for various languages with advantages and disadvantages?
Here is the information I would think would be useful about each language:
practical applications
Hello World Sample
Compilers
Speed Comparison's for various programs
Advantages
Disadvantages
Learning Curve
Resources
Some languages I would be interested in Perl, PHP, C, Java, .NET, VB, Qbasic, LISP, Assembly, Python, Ruby. - rubycon, on 10/12/2007, -0/+1Just in case anyone is still reading this:
I have implemented the exercises in Ruby. It can be found here:
http://www.rubyrailways.com/implementing-15-exercises-for-learning-a-new-programming-language/
Digg is coming to a city (and computer) near you! Check out all the details on our