Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm new to programming, and I'm working in C. I know that this is structured programming but if I use blocks, say for local variables:

{
 int i;
 for(i=0; i<25; i++){
   printf("testing...\n");
   }
}

Doesnt this make it kind of object oriented-like? Is this still structured?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

Using such code blocks does not really have anything to do with OOP. With that code you are just printing the statement 25 times.

Try looking at concrete differences between say C and Java in terms of design and application.

share|improve this answer
    
that helped a lot. Cheers everyone! –  tapiwa 'tp' Feb 3 '12 at 23:00
add comment

One of the persistent myths about Object Oriented programming is that you need to use a special language to program in an object oriented fashion.

The truth is that you can write OO code in any language, and you can write non-OO code even in languages like C++ or Ruby that are very focused on OO.

In your example, though, the answer is no: your code is strictly procedural code.

That doesn't mean you can't write OO code in C, just that you haven't this time.

Consider http://en.wikipedia.org/wiki/Object-oriented_analysis_and_design for some of the background theory, and consider that the original C++ compilers were just a front-end to a C compiler.

share|improve this answer
    
To add to your comment, I find the concept of Abstract Data Types easier to understand initially than OOP. Of course I can't go back in time and 'unlearn' OOP, but at the time understand scoping an encapsulation in the context of OOP was very difficult. Abstract Data Types are one way to implement OOP in C and an understanding of them is very valuable, in my opinion. en.wikipedia.org/wiki/Abstract_data_type –  Jonathan Rich Feb 3 '12 at 22:22
add comment

What you've illustrated is minimizing variable scope, which is a good thing to be doing.

You could call that a form of encapsulation, which is one of the tenets of object-oriented programming, because you're using a mechanism of the language to restrict visibility of data to only the code which needs to see it. Calling that object-oriented programming would be quite a stretch, though.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.