encap/OO use question

Started by
60 comments, last by RolandofGilead 22 years, 1 month ago
First off, don''t misunderstand me, I use C++ and OOP. My pet peeve is, and I''m sorry I don''t remember who said it cause it was on a forum here, it has become ''over-engineered'', too many terms, was made more difficult than necessary. In that vein, how odd it is that you can encapsulate data by using different namespaces and files in C, while even with OO the coding practice is still to use many .cpp files, really what''s the point of double encapsulation or that C++ while being a superset as far as I know still uses the old C standard or that, again, as far as I know all class data is stored on the heap just as is all global data. Finally, the real problem is the OO programmers who are snotty for all the wrong reasons. I''ve read enough flame wars to understand that both sides have strong proponents. Fine, let them, but just understand that C as I see it is procedural, it is not like some old version of basic that was interpreted and had GOTO statements everywhere that wound up being spaghetti code if you tried to write a large program. OO is like an extension of procedural. You could say that procedural programming encapsulates code the way OO encapsulates data, it''s much easier to manage what time something is used. It''s kind of poetic I think. Back to the subject of the post... I always thought encapsulation and OO were good for team projects and if a programmer released source or a library, but from what I''ve read recently in the forums is that this is also used on your own code to prevent access that should not occur(and get rid of globals). Is this true? I first learned a little basic, got introduced to asm, and started C. I have since finished C++ and the magic of OO. (So I am familiar with both styles.) Now, when I first saw that I no longer had to pay attention to formatting my printf''s and could just use cout, I thought to myself, "It''s about time they created a language for lazy people cause let''s face it, we programmers are by default lazy." If all these design considerations are to be used this way it seems that C++ was developed for both stupid and lazy people. Even if I don''t shield my attributes, how could I possibly be stupid enough to allow say, my graphics code to corrupt some ai data. So was C++ designed for stupid lazy people?
Advertisement
Thats a big post!!

Anyway, c++ isnt for dummies... Its stupid to think like that.
Whats the idea, ie, for writing allways that stupid formatting string in printf? boring...

We, programmers, need to avoid writing repeated code and also need simplest and readeable code.

In these days, processors are very fast and they can execute milions instructions per second, and because of that we can write code in a much higher layer.

This doesn''t make us stupid and lazy!!

Supose this:

C:
struct vector
{
... data
};
vector soma(vector a, vector b);

vector a = {10,0,3}, b;
vector c = soma(a,b);

C++:
class vector
{
... operators etc
};

vector a(10,0,3), b;
vector c = a + b;

witch code is more elegant? and more simple?

BTW, if you think so, then write your code in asm...

PROgrammer
Yawn! This is a rather lame attempt at trolling. You''ll have to try harder next time...
quote:Original post by RolandofGilead
So was C++ designed for stupid lazy people?


The fact is, the tools are made that way, to use them or not is your choice, if you feel that it is stupid, then don't use them...

Not all basic code is speghetti code. I remember when I wrote my game in Quick Basic Xtended, there weren't any goto, gosub of any type for that matter. It was stricly functional code.

You say you learned ASM, well then why don't you write your code in ASM?

One last thing, a bit more respect for fellow programmers would be a good thing. Before calling others stupid, why don't you look at yourself and see who's the stupid one....





"And that's the bottom line cause I said so!"

Cyberdrek
cyberdrek@gdnmail.net
Founder Laval Linux

/(bb|[^b]{2})/ that is the Question -- ThinkGeek.com
Hash Bang Slash bin Slash Bash -- #!/bin/bash

[edited by - cyberdrek on March 18, 2002 8:52:41 AM]
[Cyberdrek | ]
quote:I always thought encapsulation and OO were good for team
projects and if a programmer released source or a library,
but from what I''ve read recently in the forums is that this
is also used on your own code to prevent access that should
not occur(and get rid of globals). Is this true?


Yes, it is!
By hiding methods or variables as private or protected you prevent YOURSELF from calling them directly.


The Wild Wild West - Desperado!
The Wild Wild West - Desperado!
Must ... resist ... flamebait ... gnah!
Private and protected variables makes your program more stable and secure.

If you want to access them then you might want to make methods like GetVariable() and SetVariable(newvalue) and the last one checks if newvalue is secure and valid.

In c++ you got also virtual methods wich are good for making interfaces and get more flexbility. Static methods and variables are great too.

Supose:

class Logger
{
static std::map files;
...
public:
static void AddFile(std::string file);
static void Log(std::string file, std::string text);
};

then anywere in your code you can do
Logger::AddFile("main");
...
Logger::AddFile("netclient");
...
Logger::Log("main", "any log message");
...
Logger::Log("netclient", "connected");

at the end, the code is very simple, and nobody can mess with the files(map).

The idea here is to make all module. Then anyone can download your Logger class and use it or expand it.

PROgrammer
quote:Original post by RolandofGilead
So was C++ designed for stupid lazy people?


Maybe smart lazy people. Less work for the same results, and you get the compiler to do some of your error checking!

Lazy is good! :D

(oh yeah, modular code tends to be easier to... well, mod, or something. I dunno)

"Eagles may soar, but weasels don''t get sucked into jet engines."
"There is only one everything"
I used to actually think the same thing. Coming from a C background, reading about C++ when it was first introduced I was like "Well this is for C programmers that make alot of mistakes..."

But it is alot more than that. The OOP paradigm is more than just the black-box theory. It is a mindset of programming practices that allows you to more easily model real world objects with code. When used properly, OOP reduces development time by defining data, behavior, and dependencies for each element of your problem at hand. It provides a more intuitive means of documenting your large projects and a cleaner way of extending functionality into new objects.

Let''s see you emulate complex polymorphism and multiple inheritance in C while maintaining a reasonable level of work efficiency and readability.

Peace,
Geek
I never said the programmers were stupid and lazy,
only that we are by default lazy.

siaspete and Sabreman: so could you give me some pointers?

the Speed Bump: Your answer makes sense, I agree, thanks for the
insight.

This topic is closed to new replies.

Advertisement