What's the best way to learn programming??

Soldato
Joined
18 Aug 2006
Posts
10,053
Location
ChCh, NZ
I played around with C-Sharp a month or two ago but lost motivation due to it just becoming impossibly complex after a while and I found myself writing many lines of unnecessary code to achieve something simple. I'm not interested in working in IT but just playing around with XNA and modifying other people's code to achieve something different is what I'm after.

How do I go about learning proper programming and proper techniques on a hobbyist level? How did YOU learn your skills? Any good books or good tutorials?
I did Google and found a boatload but the age old problem persist, the author usually assume too much and lose me very quickly.

I have LOADS of time on my hands and wanna do this properly this time round.
 
I had that problem when I first tried C#. I came from a PHP background, so I was used to being able to do a lot of things sloppily, whereas C# forces you to do everything you want to do explicitly, which frustrated me a lot at first. My advice is just to stick with it and persevere.

Try and think of a small pet project to do, be it something that's useful in a practical sense (e.g. a backup tool), or just something interesting to sharpen your programming teeth (e.g. a simulation of the Game of Life). See how far you can get with it, and if there are bits you can't manage, read about them, practice them in small, throw-away applications, and try putting them to use.

As for books, I couldn't recommend Programming C#, Fourth Edition by Jesse Liberty enough. It's certainly helpful to have a book, or at least some reference material, as it helps guide your programming style in the right direction, which might not otherwise happen if you just do it by yourself. An example is object oriented programming, which is a lot easier to pick up if you have a book guiding you through it in the language you're learning.
 
got to agree

find yourself some useful project, work on that. then when thats done work on something else

its as simple as that really.

ive used books in the past but tbh i find the net the best place for help and assistance

chances are if you stuck with a problem or an error message somebody on the net has come across it before.
 
Start with pascal, it's stupidly simple and has helped me a lot when it's come to learning C this year. It was actually designed to teach the ways of C programming :)
 
HTMLHugo said:
ive used books in the past but tbh i find the net the best place for help and assistance

chances are if you stuck with a problem or an error message somebody on the net has come across it before.
Agreed—the internet is certainly the best place to find help on a specific matter, but I find that books are vastly more useful when it comes to learning a language from scratch, especially a fairly complicated, object oriented one like C# or C++. They help guide you through the more complicated aspects of a language, and just provide a structured, ordered way of learning it.
 
I wouldn't bother with Pascal tbh because it was the first language i learnt and when i moved to C i found things were, although subtly different, different enough to cause a lot of headaches.

I think C is a very good first language to learn. The number of languages based on it are numerous so chances are there will be lots of similarities when you move to another language.

I've just started down the C# road myself but final year of uni has put an end to that really! I was using Visual Studio 2005 though which is very helpful for cutting out the mundane code writing! I got it free off the microsoft website. I've lost the link i'm afraid but a search or two should turn it up!
 
Thanks for all the replies. I've slaved away many hours at some very tough programs and what irritate me most about most tutorials or books is that they show you HOW to do it, but not WHY in any given problem.

Example, I can write complex looping structures but at the end have no idea how I got to my result.
Another example, I can write a program that interface with any database but I don't understand a thing about the code i wrote. I just know how to write it.
Hope it makes sense. Hard to explain really :eek:

I've tried reading books on the art of programming but I was waaayyyy out of my technical depth and gave up after giving it one hell of a go.

Anyway, I'm looking at that book inquisitor and will prolly go buy it tomorrow
 
robmiller said:
I'm so doing this :cool:
I actually coded a version of this in C# the other week.
It's a pretty simple concept but quite cool.

Another one that I found interesting was a mavity simulator.
My version lets you click on the screen to add another object to the system where you click. All the objects follow Newton's laws of gravitation and it's interesting to see the interactions.
 
A simple project I've used for learning is to create a Safari park, which has animals that need feeding a set amount per cycle, then later developing into predator+prey with birth rates and so on. Started simple, got very complex. Is good in many ways, I took it from a Design Pattern POV, but can easily see it useful for generic coding practice.

Very similar to Game of Life now that I've read up on it.
 
regulus said:
Thanks for all the replies. I've slaved away many hours at some very tough programs and what irritate me most about most tutorials or books is that they show you HOW to do it, but not WHY in any given problem.

Example, I can write complex looping structures but at the end have no idea how I got to my result.
Another example, I can write a program that interface with any database but I don't understand a thing about the code i wrote. I just know how to write it.
Hope it makes sense. Hard to explain really :eek:

I've tried reading books on the art of programming but I was waaayyyy out of my technical depth and gave up after giving it one hell of a go.

Anyway, I'm looking at that book inquisitor and will prolly go buy it tomorrow
Looking at other peoples code is a good way to learn. You just need to learn how to backward engineer it.

Best way is to use the debugger, step through the code watching all the variables change, it will shed light on how the code works exactly. Any questions you need to ask, msdn or programming forums should help.
 
HTMLHugo said:
chances are if you stuck with a problem or an error message somebody on the net has come across it before.
v.true

this might help in that :
www.google.com/codesearch



Book:
Code Complete (Microsoft Programming)
by Steve McConnell

t'was was pretty good, till I lent it to someone who didn't return it :-(
(people like that I list somewhere between traffic wardens and pedos)


.
 
did "game of life" in java earlier this term at uni. was easy to code but gave you a chance to use the GUI.

i'd start in java as it is easy to use. then move into C and C++.

daven
 
If you don't understand code structures then forums are your friend. People are much better than those author type things ;)

It took me ages to get my head around multi-dimensional arrays but after bugging people of forums for long enough i have my head around them now. Just.
 
I still cannot grasp the concept of classes and the inheritance from them. Simple as they may seem, I just don't "get" them. I sort off know how to use them, but it'll make my life SOOO much easier if someone can explain them to me if simple, layman English. I have off course loads of other stuff I still don't get, but classes would be a good start.

Btw, what forums were you asking on?

Edit: Luckily arrays in all its shapes and forms have been kind to me...so far.
 
ok a class encapsulates (brings together) attributes and methods.

so basically a class is a collection of variables and methods. think of it like a book. a book will have letters, words, sentences etc. and you will be able to turn a page, check if you are at the end etc.
you could incorporate all that into a class, then any book you made, be it an encyclopedia or a novel would INHERIT all these methods by extending the book class, but could then add their own too.

daven
 
Right, well it’s useful to think of classes as blueprints; they’re abstract definitions that aren’t actually solid or tangible. You instantiate classes to create objects, which are the actual products of the blueprint. The objects have their own data associated with them and can be kicked around from one place to another.

The idea behind objects and classes is to allow you to base your coding on a collection of self contained, self-defined ‘things’, whose internals you don’t have to worry about, and which can perform actions on themselves and communicate with other ‘things’ (for want of a better word).

As for inheritance, imagine you have a blueprint representing a generic vehicle: it specifies various properties like maximum speed, mass, etc. Now imagine another blueprint that further refines this definition to create that of a car. It may now include such properties as engine size, number of seats, number of doors, and so on. This new blueprint (the sub class), derives from/inherits from/extends the more general definition of a vehicle (the super class) to make it more specialised. Objects of the sub class can be used in any context that objects of the super class can, as it must, by virtue of deriving from it, include all of the super class’s properties (although it may modify them—such modifications form the basis of polymorphism).

Hope this has helped a bit :confused: Be sure to get that book, though—it can probably do a much better job of explaining it than me.
 
Last edited:
Ok, here's my understanding from what you guys just wrote.

I write my base class and leave it be to do its "thing". I inherit from class into another class with EXACTLY the same properties to which I can add or change as necessary. It's essentially the same class but this time changed a bit to accomplish something else.

I understand the concept well (hopefully :eek: ), but I cannot immediately see the value of inheriting from the base class. Why not just load all the attributes, variables and methods into the base class and call them from there? Or am I understanding this wrong?

edit: Inquisitor, you write very well but you get very technical in using a lot of jargon. I understand 100% what you're saying and you say it well, but if a complete newbie was reading that he would run away screaming.
Daven, you are more beginner friendly! :p
 
Last edited:
regulus said:
I write my base class and leave it be to do its "thing". I inherit that class into another class with EXACTLY the same properties to which I can add or change as necessary. It's essentially the same class but this time changed a bit to accomplish something else.
Almost. The useful thing about deriving from a super class is that you don't have to re-implement all of the methods and properties that were exposed by the base class; you just ignore them and they're still available in the sub class. This leaves you free to modify/add to the functionality available through the class. Also, you're not changing it to accomplish something else; strictly speaking, you're adapting it to accomplish something more specific, or in a more specific way.

regulus said:
I understand the concept well (hopefully :eek: ), but I cannot immediately see the value of inheriting from the base class. Why not just load all the attributes, variables and methods into the base class and call them from there? Or am I understanding this wrong?
Well, a good example of inheritance in C# (there are actually thousands) is the Stream class and its derivatives. Stream is abstract, meaning that it cannot in itself be instantiated; all of the methods it specifies are not actually implemented in the Stream class—the methods have no actual code bodies to them, just a semi-colon at the end of the line. Instead, in order to use it, you must create a sub class of it that instantiates all of the abstract method and property definitions and instantiate that sub class.

For example, the MemoryStream class derives from Stream and implements the base methods in its own particular way based on what it does (writes and reads data to/from an array of bytes). Because it implements all of the methods that were specified by Stream, it can be used by any method that accepts a Stream as a parameter. The method doesn't care about how the particular version of the Stream it's been given works, it just uses it. You could pass it any one of the Stream sub classes, for example, FileStream, NetworkStream, etc.; they all have their own implementations of the different methods and properties specified by Stream itself.

Here's an example of an almost useless method that writes a single byte to a stream:
Code:
public void WriteByte(Stream stream, byte value)
{
    stream.WriteByte(value);
}

Since this method will take any object that either is a Stream or derives from it, the following two lines of code are both equally valid:
Code:
WriteByte(new MemoryStream(), 10);
WriteByte(new FileStream("test.bin"), 10);
The WriteByte method doesn't care how the Stream object is writing the byte, it just cares that it will do :)

regulus said:
edit: Inquisitor, you write very well but you get very technical in using a lot of jargon. I understand 100% what you're saying and you say it well, but if a complete newbie was reading that he would run away screaming.
Daven, you are more beginner friendly! :p
:p
I did try to offer a bit of insight into the reasoning and theory behind object oriented programming as well, though, rather than just giving a description :)
 
Last edited:
You wouldn't necessarily have all the same methods, variables etc. in all of the subclasses though.

Let's imagine you have a Shape class. This shape class has a Draw method which draws the shape.
Obviously for a generic shape we don't know what to draw so we create subclasses which override (have their own implementations of) the Draw method.

So, we create Triangle, Square and Circle classes.
In the Triangle class the Draw method draws a triangle and the Square and Circle classes draw their own respective shapes.
We can also then add extra methods to the subclasses though, for instance we could create a GetRadius method that returns the radius. Obviously this only makes sense for the Circle so we put in here and nowhere else.
Thus, Circle derives from Shape and has all the properties of a generic Shape but also extends it to add extra functionality.

Now, the real beauty of Object Oriented programming is that we can say the Triangle, Square and Circle are all Shapes and therefore everything that can be done on a Shape can be done on its subclasses.
So, we can create a procedure to draw a Shape.
We want the procedure to be able to draw any of the Shapes we have defined so we create an input parameter of type Shape and then invoke the Draw method on our Shape object.

Now, because Triangles, Squares and Circles are all Shapes we can pass any of these objects into our procedure. We are calling Draw on the Shape Object, but if we pass a Triangle into our procedure then it will draw a Triangle, similarly for Squares and Circles.

The best bit is that if we want our procedure to draw another, completely different shape, we don't have to modify it one bit.
All we need to do is to create another class, say Hexagon, that inherits from Shape. This new class is also a Shape and we can pass it into our procedure and it will draw whatever we have made it draw in our new class.
 
Back
Top Bottom