6

If somebody has to start learning to program, where should he/she start? Should he start to write procedure-oriented programs or jump to OOP?

Saurabh
  • 294
  • 4
  • 8
  • 3
    http://programmers.stackexchange.com/questions/89453/is-oo-programming-really-as-important-as-hiring-companies-place-it maybe this question will be interesting for you to know more about reasons behind OOP. – deadalnix Sep 08 '11 at 12:07
  • 1
    You can take a hint from MIT and start with learning SICP/Scheme which is mostly functional. – dietbuddha Sep 08 '11 at 16:56

8 Answers8

13

The best thing you can do is to get a handle on all the paradigms. I'd suggest the following order:

  1. Simple procedural programming: just getting basic sequential programming techniques down.
  2. Structured programming: Top-Down design, Abstract Data Types, Modules.
  3. Functional Programming: Working without side-effects, functions as first-class objects
  4. Object-Oriented Programming: Abstraction, Polymorphism
  5. Very low-level programming, i.e. assembly language: working with the hardware, number of registers, cache, memory, SIMD instructions, optimization, and generally an appreciation of how much easier compilers and interpreters make our jobs.
  6. Multiparadigm-programming: Combine all of the above using the best tool for the job when appropriate

And then you can try some more esoteric styles, such as Logic Programming (Prolog), and Concurrent Programming (Communicating Synchronous Processes, OCCAM).

You can several steps in one language (Python would cover most of the bases), though it's probably better to do 3 in a relatively strict functional language (I'd suggest Lisp), and 4 in a relatively strict OO language (Java, C#). You don't have to go extremely deep in any of the languages, just do a Code Kata or two in each to get a feeling for the paradigms.

Having all (or just several) of them under your belt will make you a more versatile programmer, even if you never really go deep into one specific paradigm again.

Joris Timmermans
  • 8,998
  • 2
  • 36
  • 60
  • 1
    Generally a very good answer, but solving a problem or two in Java or C# won't teach you object oriented programming. It takes years to become a good OO-programmer/designer and to truly understand it. – Falcon Sep 08 '11 at 12:59
  • +1. Although I must say inheritance is to OOP what hats are to carpentry. There's no particular reason why C couldn't have single inheritance for structs for example. – back2dos Sep 08 '11 at 13:02
  • @Falcon - true, but OOP is the most likely "professional" path out there, and thus likely to be covered deeply at a later time. I'd much rather see more well-rounded developers that I can teach good OOD (not OOP) than "OOP for everything!" people. – Joris Timmermans Sep 08 '11 at 13:04
  • @back2dos - you're right, inheritance is an implementation detail, it's polymorphism that matters. I'll edit my answer. – Joris Timmermans Sep 08 '11 at 13:05
  • @MadKeithV: I fully agree with everything you said in your answer, I just felt I need to mention it for the reasons [deadalnix posted in this answer](http://programmers.stackexchange.com/questions/89453/is-oo-programming-really-as-important-as-hiring-companies-place-it). Anything in your list can be understood and used pretty quickly, but most novices fail to understand and use object orientation correctly. – Falcon Sep 08 '11 at 13:19
  • @Falcon: in my experience people who have come from a POP background find OOP difficult. Complete novices with the "beginner's mind" seem to take very naturally to OOP. – TrojanName Sep 08 '11 at 14:34
  • I would add some low level experience, to know what the computer is doing. – deadalnix Sep 08 '11 at 18:27
  • @deadalnix - agreed, I have learned a lot from writing assembly language and sse intrinics too. I'll add that to my answer. – Joris Timmermans Sep 09 '11 at 07:16
3

I think what you begin with isn't really important. What is important is that you know both, and fail with both.

Because you will fail. Learn from it.

All xOP are here to solve problems devellopers encounter when coding, or maintaining software. The bigger the software is, the more important it is. You can learn OOP, or POP, but at the end, you'll not understand what it is good for unless you exprience problem you have not following those methodologies.

POP, OOP and others are not just coding techniques. This is a way to think about your code. New way to think are devellopped to solve problems devellopper had with previous way to think about what they do.

Acquiring that require time, way more than learning simple techniques.

Anyway, I'll advise you to start with POP. Because at the end, you cannot do something without it. If you do OOP, you'll have clases, methods, but with methods, you'll find plein old procedural programming.

POP and OOP are not think that should be thinked at instruction level. At this point, you are doing procedural, even if you do OOP, fucntionnal, or whatverer. But doing only POP, you'll encounter problems when your software grows. OOP, functionnals, and others way of thinking your software as a whole will help you to handle the incrasing complexity of the code.

Note that thos can be achieved in pure procedural, but kinda hard, and not the way broadly used in industry.

deadalnix
  • 5,973
  • 2
  • 31
  • 27
3

I think that before you start doing oop programming you should have a basic understanding of programming as it used to be done. It's important for a programmer to know why he/she is using oop and i think the fastest way to understand this is by starting without, begin with the basics of memory manipulation and math.

hcb
  • 161
  • 1
  • 5
  • 1
    I second doing it the historic way. But then, he should learn also functional programming between POP and OOP. – Ingo Sep 08 '11 at 12:27
  • 1
    You seem to be saying "as it used to be done" as if it's a single (procedural) style. It's not. There's more to programming than procedural vs OOP. – Joris Timmermans Sep 08 '11 at 13:07
1

I suggest a simple, non-obstructive environment such as Squeak or Ruby with Shoes.

There's no reason to start programming in a procedural manner. Neither coding closer to the computer nor re-enacting the history of programming will help you find a good entry point to programming.
When you first learn, how to drive, you won't do it in a steam engine, although it's historically correct and will help you actually see on what basic principles engines are based.

First learn how to do it, gather some intuition and then push forward for an ever deeper understanding.

back2dos
  • 29,980
  • 3
  • 73
  • 114
0

I'd say go for learning both. If you don't know how to program yet, close your eyes and choose Python as your first language. It allows you to put in your procedural concepts while still being object oriented. Even using standard Python libraries/types will give you a feel of OOP and you will excel in the Science and Art of Programming. Then once you get the feel of the language itself, go for OO concepts.

Once you have the concepts right, you can give C++ or even Java a shot. But as a complete beginner, I'd recommend Python first.

OOP, Procedural programming, etc are just different ways to model and solve problems, and you should definitely have both under your belt.

regards,

Yati Sagade

PS: the second person in the above answer refers directly to the third person in your question :)

yati sagade
  • 2,089
  • 2
  • 19
  • 27
0

I would reccomend OOP first, here's why:

First Language

You want to start off with OOP. The reason is that this is primarily what is used in the real word, and you it's always easier to learn a concept like that as a first language, instead of a second one. I always hear people saying they don't understand the concept of OOP, theses are usually POP programmers that are transitioning to OOP. My first language was Java, which is an OOP programming language, and I never had a problem understanding the concept, because I didn't know anything else.

OOP can do everything POP can do

The other thing is that you can always use an OOP language as a POP if you want to. for example, in java, you don't have to use more than one class if you don't want to, and it becomes fairly easy to understand what POP is like (OOP has all of the features of a POP language, but it is more dynamic and reusable, but if you don't want to, you don't necessarily have to take advantage of those features) the same should apply with something like C++ vs C

Ephraim
  • 285
  • 2
  • 8
  • 1
    -1. For one Java is a poor choice for OOP and secondly, you cannot do everything in Java you can do with C. Not even half of it. – back2dos Sep 08 '11 at 13:00
  • but you can do everything from C in C++ which is also OOP – Ephraim Sep 08 '11 at 13:07
  • 5
    @back2dos, why is Java a poor choice for learning OOP? And why is it a factor in learning to program that one should be able to do "everything" (how you define "everything" btw?) in his/her first programming language? – Péter Török Sep 08 '11 at 13:07
  • @Péter Török: I never said one should be able to do everything. However Ephraim claimed, that you are able to do it and that's plainly wrong. Java is a poor choice for learning OOP, because in Java OOP is optional. – back2dos Sep 08 '11 at 13:45
  • @back2dos, what do you mean by "in Java OOP is optional"? – Péter Török Sep 08 '11 at 13:49
  • 2
    @back2dos: Have you ever programmed in Java at all? Java is based primarily on the object orientation paradigm. – Falcon Sep 08 '11 at 13:51
  • @Falcon: What you statement is a common misbelief yielded by Sun's successful agenda as promoting Java as the defacto-OOP standard as a response to OOP being hyped as the silverbullet in our industry. The core aspects of OOP are encapsulation and polymorphism, both of which are optional in Java, building classes with public fields or type relationships against final classes for example break them. Java is just C++ minus all the rope to hang yourself with. Java is *class*-based, which is not inherently *object*-oriented. Compare it to Io, Smalltalk, Ruby or Objective-C. – back2dos Sep 08 '11 at 17:54
  • @back2dos: You have a strange definition of object orientation. Last time I heard about it, it was all about objects passing messages. I don't really know what you mean tbh, at the moment I think that you consider only dynamic polymorphism true object orientation. That's a pretty narrow point of view imho. – Falcon Sep 08 '11 at 18:44
  • @back2dos: So please explain why it's possible to program "not object oriented" (by your definition) in Ruby as well? I can totally break object orientation (by your definition) with Ruby, too. – Falcon Sep 08 '11 at 18:53
  • @Falcon: For one "message passing" is in fact the definition provided by Alan Kay. Although arguably somewhat narrow, I think it's still a far better idea of object orientation, than the popular: "Look at Java, that's OOP!" (TM). All I am saying is, that in Java you *can* write object oriented code, but actually chances are quite slim, given the way Java is commonly taught and used. Fun fact: the first member declaration in the official tutorial on [Java classes](http://tinyurl.com/38gdlpf) is a public field as opposed to Ruby, which doesn't even have them. – back2dos Sep 08 '11 at 20:26
0

There are many ways to Rome, but one approach that strikes me as logical is to follow the evolution of programming languages and paradigms. So you'd start out with a close-to-the-metal imperative language (probably C). Then you'd build from there, discovering abstractions that people have invented to make managing complex code easier. So:

  1. Imperative
  2. Structured
  3. Structured, but avoiding global state
  4. Functional or OOP
  5. OOP or Functional
  6. ad libitum: Logic Programming, Aspect-oriented, Data-driven, Metaprogramming

And of course, taking the best of each in real-world programming situations.

At the bare minimum, I think a decent programmer should have had some exposure to at least one language in each of the following groups:

  • C
  • C++, Java, C#, Objective-C, ...
  • Python, PHP, Perl, javascript, ...
  • Lisp, Haskell, ML, Scheme, Clojure, F#, ...
  • brainfuck, malbolge, befunge, intercal, ...

(I'm serious about that last category: while you won't do any serious programming in any of them, looking into them definitely gives insights into the way computers and the human mind work)

tdammers
  • 52,406
  • 14
  • 106
  • 154
0

This question is a bit like asking men if they think being circumcised is better than not being circumcised - there seems to be a remarkable correlation between whether or not they are circumcised and whether or not they think it's better. Of course, once you've been circumcised it's hard to go back. ;-)

As someone who first learned procedural programming, I (and quite a few of my peers) initially struggled at first with OOP. Having spoken to people whose first experience with programming was OOP, it seems they found it a much more natural way of working. This may be because they weren't trying to make it fit with their pre-existing procedural approach, trying to impose it, if you will. Or it may just be that they were smarter than me and my friends (very likely).

TrojanName
  • 373
  • 2
  • 12