0

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?

Dynamic
  • 5,746
  • 9
  • 45
  • 73

3 Answers3

3

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.

Daniel Pittman
  • 3,660
  • 21
  • 19
  • 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. http://en.wikipedia.org/wiki/Abstract_data_type – Jonathan Rich Feb 03 '12 at 22:22
0

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.

arin
  • 430
  • 2
  • 12
0

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.

Blrfl
  • 20,235
  • 2
  • 49
  • 75