Hacker News new | ask | show | jobs
by filkatron 4546 days ago
Relative noob here, I'm learning programming in general and I picked C to start with. My university courses are pretty shitty so I have to do it by myself. OOP is pretty repulsive to me. I don't know why. Too many abstraction that I can't see clearly.

Would any of you recommend me to try and get the hang of OOP using C or should I just pick up Java or C++ ?

(sorry if this is a inappropriate comment on this post)

8 comments

To just get the hang of OOP, you might be better off starting with Python or Ruby (or some other language with a REPL). Although you can do OOP style programming in C (and it's a fun exercise), there's a lot of low level stuff that's really interesting but not particularly relevant to the basic concepts of OOP.

If the choice is between just Java and C++, I'd go with Java, but it probably depends on what your long term goals are.

In any case, learning any language can't hurt, so I don't think there's any danger of making the wrong choice--unless you get so stuck that you're not making any progress. Just pick whatever "fits your brain" then branch out later.

I would suggest Java. It has a really clean object model, is statically typed, and if you use Eclipse it will compile-as-you-write to highlight errors, suggest fixes, and autocomplete a lot of useful stuff like methods you can call on an object.

While you are at it, read "Effective Java" by Josh Bloch--it's full of excellent advice about OOP, and applies way beyond Java itself.

My biggest epiphany about OOP was realizing that just because you can use inheritance, you don't have to use it everywhere. You read a lot of toy examples where you have e.g. a shape, then you have children like square, rectangle, etc. and try to do everything this way in your projects. But it's actually often a really bad idea to overdo it, and Effective Java has some good explanations on the tradeoffs.

Consider a dynamic language to get a grounding on the abstaction. OOPS concepts make more sense in those especially if your doing windowing and graphics. May be worth it to look at smalltalk or ruby.
Perhaps you could forget the buzzword and just learn to code well in your chosen language.

Then try another language -- preferrably one that is quite different from what you started with -- to learn a completely different approach.

Unless you're working on ancient software or writing an OO programming language that translates to C, you really shouldn't need to worry about OOP in C. I suggest learning as much as you can about C and then graduate to C++. Java would be fine, too (as would C# or Python or whatever), but I personally like writing C++ whenever I can. It's a nice blend of low-level system programming and high-level abstractions. C++11 is even better with standard threads, clocks, promises, futures, anonymous functions, and so on.
You could try Objective-C. It's proper OOP with messages, and you can write normal C style stuff. None of C++ stupidity (like cout<<"Hello World", yuck).
Except Objective-C is Apple's toy.

GNUStep does not count, as it is ages behind Cocoa.

Perhaps the kinds of applications you've build don't lend themselves particulary well to OOP methodologies. Certainly OOP is very useful in most "business" apps.
Use GObject[1] from GLib.

[1]: https://developer.gnome.org/gobject/stable/

Vala is a nice C#-like language based on gobject. It also has wrappers for most popular C libraries.

https://wiki.gnome.org/Projects/Vala/Tutorial