Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Succinct

Design speed and reusability: c vs. c++

This topic is 6186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I work in a small c++ shop. The office is is purely a development site. There are only programmers there, and the closest form of middle or upper management is in New York (from Pittsburgh, PA). We have a small crew - 7 programmers, 5 testers, an engineer, and a technical writer, and the environment is very non-corporate and informal. Being that my office is very informal, we don't have official "design phases" and "design documents" (much to my dismay), unless we're working on a contract which requires them, such as miltary contracts, of which we have a few per year. Because of this, many of the projects we work on are done in a "from the seat of your pants" kind of way. The lead programmer sits down with whomever is going to be tasked to handle a particular project, gives the lesser programmer some ideas as to how he wants the functionality of the program to be, who works on what parts, a small amount of coding suggetions, and the rest of it is up to the lesser programmers. This is nice and all, that we basically get to do our own thing for each individual part, but it can really be hard sometimes, mainly because of the fact that some of the programmers are a little older and are stubbornly locked in their own coding styles and methodologies, even if it is not very intuitive for anyone else to look at and/or use. All of the programmers here use c++, but there are many different interpretations of just what "c++" is. Most of the guys at work, including the boss, are old-school c proponents. They look at c++ as being a small extension to c, and still use c style programming when they can, as often as they can. I'm a c++ aficionado, and look at c++ as being basically a different language from c. Now, here's my boggle. Because we all are given the room to design our programs ourselves, we all go about it the way we've found most successful - the other guys go about it in a fairly procedural-relational, c way, while I go about it in a fairly object oriented, c++ way. I try to write modular code, and make it reusable when I feel it will be reused eventually. They write poorly structured c code, lots of times using brute force (I saw a 10k line switch statement and a 5k line function) and code duplication, small, indescript variable names, variable names that have nothing to do with the program, such as girlfriend's names and what-not, and unnamed constants all over the place. Basically all of the things you might read about in "Code Complete", by Steve McConnell, that you're not supposed to do. The thing is, they get done a lot faster than me. A lot. Now, I feel that, in the long run, I'll be better off, because I'll have a code base of reuseable, modular objects. But until then, I feel like I'm behind in the game. Heh, another problem is that these guys don't like to interface with my objects, even when I make them as simple as possible. Much simpler than the schite they write. A perfect example is the difference between the OpenGL code I write and the code they write. The work we do is not very graphics intensive. We do some neat things with graphics, but it doesn't necessarily have to be real time, such as in a 3d game. Most of the objects are fairly static, only changing orientations and position. Because of this, I have my OpenGL client/server model classed out with a very small interface, only 5 main methods or so. To use OpenGL with my objects you only need to create a server object, attach it to a particular hwnd (via a single method call), create the object you want to render, and attach it to the server (again, a single method call). New objects are derived from a base object and override a single method that describes the object in OpenGL statements. New render objects generally consist of a single method, and that is all they need to be completely incorporated into the larger projects. When they're using OpenGL, the code is different every time, it jumps all around the application in various stages of initialization, execution, and shutdown, and is hell to trace through. They don't perform any clean-up or shutdown, and generally write a jumbled bunch of indecipherable junk that is so tightly coupled with every other part of the application that changing around any lines of code could render the entire project useless. And it's not just me who feels this way. Everyone feels the same about everyone else's code - they just can't figure it out without taking a long time to go though it themselves or having the original author go though it with them. This is except for my code, which everyone agrees is easy to read, but because it's more object oriented, they don't like to look at it. Should I conform to their method? Should I start writing sloppy code that, by way of brute force, is completed more quickly, or should I continue to take longer writing more modular, reusable code? If I ever want to get another job, I'd better keep writing modular code, but I'll probably take some heat here while I do it. I've already been "scolded" by the boss for my coding techniques, such as using "const", "new" instead of "malloc" and "calloc", and using "string" or "AnsiString" (a borland specifice string class) instead of "char*". My boss straight up told me he doesn't like me using const objects. He also doesn't like me using interfaces. He feels that I should just make all member data public so it can be directly accessed... WHAT THE HECK!? I AM IN CODING HELL! Any comments or suggestions? Please? Thank you for your bandwidth, -- Succinct Edited by - Succinct on November 2, 2001 12:15:20 PM

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Succinct
Because of this, many of the projects we work on are done in a "from the seat of your pants" kind of way.


Yay pants!
quote:

The lead programmer sits down with whomever is going to be tasked to handle a particular project, gives the lesser programmer some ideas as to how he wants the functionality of the program to be, who works on what parts, a small amount of coding suggetions, and the rest of it is up to the lesser programmers.


Excellent. Are there are any vacancies?
quote:

some of the programmers are a little older and are stubbornly locked in their own coding styles and methodologies, even if it is not very intuitive for anyone else to look at and/or use.


They''re wrong.
quote:

I try to write modular code, and make it reusable when I feel it will be reused eventually.


Very good. Shouldn''t you be making it reusable whether or not you imagine it''ll be reused? You can''t always be sure what the next project will entail.
quote:

They write poorly structured c code, lots of times using brute force (I saw a 10k line switch statement and a 5k line function) and code duplication, small, indescript variable names, variable names that have nothing to do with the program, such as girlfriend''s names and what-not, and unnamed constants all over the place.


Do you mean that their data is poorly structured, or their actual code? If it''s really their code, then they ought to be willing to listen to what''s wrong.

Don''t they know you''re meant to call them ''foobar'', ''wombat'', and ''magic''?

By indescript, do you mean using ''i'' for a loop counter, or using ''i'' for a global variable? If it''s for the global variable, give them a beating.
quote:

Basically all of the things you might read about in "Code Complete", by Steve McConnell, that you''re not supposed to do.


Nice plug.
quote:


The thing is, they get done a lot faster than me. A lot. Now, I feel that, in the long run, I''ll be better off, because I''ll have a code base of reuseable, modular objects. But until then, I feel like I''m behind in the game.


You said they were older than you. That most likely means they''ve been programming for longer than you, so it shouldn''t be surprising that they can do it faster.
quote:

Heh, another problem is that these guys don''t like to interface with my objects, even when I make them as simple as possible. Much simpler than the schite they write.


Judging from your description of them, it''s not your objects they don''t like to interface with, it''s objects in general.
quote:

Should I conform to their method?


Yes.
quote:

Should I start writing sloppy code that,


No.
quote:

I''ve already been "scolded" by the boss for my coding techniques, such as using "const", "new" instead of "malloc" and "calloc", and using "string" or "AnsiString" (a borland specifice string class) instead of "char*". My boss straight up told me he doesn''t like me using const objects. He also doesn''t like me using interfaces.


I don''t like interfaces, myself. I just use classes with virtual members if I want something that''s like an interface.
quote:

He feels that I should just make all member data public so it can be directly accessed...


I love OOP, and I agree with your boss on this one. Variables should be public. It is a deficiency in the C++ language that means everyone tells you to make them private: C++ doesn''t allow a class to know when you assign a value to one of its fields. Having said that, if you''re programming in C++, variables should be private, because of the deficiency.
quote:


Any comments or suggestions? Please?



When you are employed by a company, they will generally have rules about the coding and design style that is acceptable by that company. They don''t impose that style because they are fascist (well, sometimes they do), but because it is important to have a style that everyone uses, elsewise no one can work together.

Judging from your description, it appears that your office doesn''t have a style-guide. It is important to have one. The fact that OOP is technically correct doesn''t mean it must be used: in the end what matters is that the programmers use a paradigm with which the majority of them are familiar. Your office needs a style-guide that is compatible with the programming practices of everyone who works there.

All your bases belong to us

Share this post


Link to post
Share on other sites
quote:
Original post by Mayrel
I love OOP, and I agree with your boss on this one. Variables should be public. It is a deficiency in the C++ language that means everyone tells you to make them private: C++ doesn''t allow a class to know when you assign a value to one of its fields. Having said that, if you''re programming in C++, variables should be private, because of the deficiency.



I agree. This is the only reason I use interfaces. Borland C++ actually has circumvented the c++ problem by making properties, pseudo-variables that, when accessed, in the same manner that any other public member variables are accessed, actually call a method in response to the access. Now THAT''S beautiful! I use properties when I can (when I''m sure the code I''m writing will say in Borland), but becuase I also use MSVC from time to time I have to use interfaces.

You seem to be a very informed individual, Mayrel. Nice to see your reply

-- Succinct

Share this post


Link to post
Share on other sites
Examples of global and member data variable names:
g,gx,ggx,gxx,x,zed,zax (zed and zax are always filenames, I''ve recently found out),

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Mayrel
Excellent. Are there are any vacancies?


I''ll keep you posted. My head may explode soon though, and though this will generate a vacancy, I won''t be able to tell you.
quote:

They''re wrong.


Ouch!
quote:

Very good. Shouldn''t you be making it reusable whether or not you imagine it''ll be reused? You can''t always be sure what the next project will entail.


I try to, but like I said, I feel like I''m always behind, so I don''t always, though I''d like to.
quote:

Do you mean that their data is poorly structured, or their actual code? If it''s really their code, then they ought to be willing to listen to what''s wrong.


Both. You should see some of the structures used, and the code that uses them. You should see some of the code in general... ACK! I mean, the actual code is usually good. But the structure of it usually starts off like how an optimized section of code might end up looking when finished. Just hell to work with.
quote:

Don''t they know you''re meant to call them ''foobar'', ''wombat'', and ''magic''?


Heh, I''ve seen ''foo'', ''bar'', and ''foobar'' in a few places. "Just like the examples!" - arrgh...
quote:

By indescript, do you mean using ''i'' for a loop counter, or using ''i'' for a global variable? If it''s for the global variable, give them a beating.


Examples of global and member data variable names:
  
int a,b,c;
int ww,hh,xx,xa;
FILE *zax; // zax is always a file pointer

FILE *zed; // as is zed

int a,b;
bool da;
int x,xx,y,yy;
int scaleval,smod,iran,ggx;
BYTE *smode, *mode;
int orin,olorin;
DWORD tic;
BYTE *dev;
float *fcrot;
int icrot;
int a,b,x,y,i,j,k;
DWORD tic1;
int ggx,ggy, nggx, nggy, uggx, uggy, vggx, vggy, cenx, ceny, ncenx, nceny, ucenx, uceny, vcenx, vceny;
float goff, noff, uoff, voff;
int crossx, crossy, downx, downy;

And one of my favorites:
  
void __fastcall TDDepth::DrawButtonG(int w)
{
int a,x,y,xx,yy,i,j,xa,ya,xb;
x=butts[w].x;
y=butts[w].y;
xx=butts[w].w;
yy=butts[w].h;
...
}

So, yes, it is normal variable names, not unimportant ones such as loop counters.

I''m sure they make sense to whomever wrote them, and they may in context, but I''m used to code you can understand by glancing at it. I''d say that makes development times a little quicker... Maybe it''s just me.
quote:

Nice plug.


Thanks I''ve always liked that book, and I recommend it every time I get the chance to.
quote:

You said they were older than you. That most likely means they''ve been programming for longer than you, so it shouldn''t be surprising that they can do it faster.


Yes, but I''ve been programming for a few years now, myself. They''ve only got a few years on me. Not too long. The extra programming time they have doesn''t seem proportional, I think. Granted, I''ve only been doing it professionally for a short time, now, but I''ve been -cough- unemployed -cough cough- for awhile before hand, a time during which I spent most of my time programming and sending out resumes
quote:

Judging from your description of them, it''s not your objects they don''t like to interface with, it''s objects in general.


Very true. That makes me feel good. Does wonders for my ego
quote:

Yes.


Darn. I''ve gotten similar sentiments from friends via e-mail.
quote:

No.


Good!
quote:

I don''t like interfaces, myself. I just use classes with virtual members if I want something that''s like an interface.


I usually start off that way, but a complex object can have multiple interfaces (like COM objects). I don''t necessarily multiply inherit a bunch of virtual interfaces, but I do generally seperate sections of a class''s definition into groups of interfaces, which are a set of interface methods all used in the same general context, and internal methods.
quote:

I love OOP, and I agree with your boss on this one. Variables should be public. It is a deficiency in the C++ language that means everyone tells you to make them private: C++ doesn''t allow a class to know when you assign a value to one of its fields. Having said that, if you''re programming in C++, variables should be private, because of the deficiency.


I agree. Other, higher level(?) languages do notify objects when their members change. If c++ did this, I wouldn''t like interfaces, either. This is the main reason I use interfaces - to notify the object that it''s changing. Thank goodness for Borland C++ Builder and it''s ANSI extensions!
quote:

When you are employed by a company, they will generally have rules about the coding and design style that is acceptable by that company. They don''t impose that style because they are fascist (well, sometimes they do), but because it is important to have a style that everyone uses, elsewise no one can work together.


I agree. I would love this, actually, even if it was saying that everyone had to use commented assembly language, exclusively. Just so everyone knows how to write their code, what they''re looking at, and doesn''t have to figure out exactly some other programmer is trying to express.

Programming is like speaking another language, and writing a program is exactly like trying to write a story in a second language. The quality of the program will -usually- be based on the author''s command of the language, and his ability to express himself in terms of it. If someone is writing a paper in German, and another German speaker has to read it, it would benefit the reader if the author didn''t use a German form of Pig-latin to write the paper, which is the equivalent of what I see here in my shop sometimes.

Everyone here has their own very subjective style, and no one is willing to change it for the sake of uniformity and professionalism.

Hungarian notation was easier to understand the first time I''d ever seen it than a lot of the code here.
quote:

Judging from your description, it appears that your office doesn''t have a style-guide. It is important to have one. The fact that OOP is technically correct doesn''t mean it must be used: in the end what matters is that the programmers use a paradigm with which the majority of them are familiar. Your office needs a style-guide that is compatible with the programming practices of everyone who works there.



Again, I agree. I am the only person, I think, with a few reservations, who''s heard of a style-guide, let alone read anything about them (again, "Code Complete" comes to mind, as does "Writing Solid Code" by Steve Maguire). I still use funtional based paradigms where it is more applicable, such as simple file I/O, image data, and array manipulation, among other things, but I tend not to mingle the two too much. Sometimes here, though, everything is a hybrid.

But, as far as OOP comprehension, some of the guys here are just too stuck in c. A couple of the programmers started out in c++, and hate what goes on here every bit as much as I do, but it''s up to the boss, and he just doesn''t feel like doing it.

/sigh

Oh well. I don''t really mind, though. They could tell me to write japanese code in assembly language, on paper, in a closet, and in the dark, and I''d still be happy to be putting food on my table with it. I just like programming, but, hey, we can all vent, can''t we?

At least it''s not just me, though. It''s not just me.
*Keeps telling himself this.*

Again, thank you for your bandwidth.

Share this post


Link to post
Share on other sites
MSVC6 has property extentions. I hate them. Side-effects are evil. If a property is public, it damn well better be an object.

From the Connection15 interface of the ADO typelibrary:
#import "C:\Program Files\Common Files\System\ADO\msado15.dll"
  
__declspec(property(get=GetConnectionString,put=PutConnectionString))
_bstr_t ConnectionString;



quote:

...such as using "const", "new" instead of "malloc" and "calloc", and using "string" or "AnsiString" (a borland specifice string class) instead of "char*". My boss straight up told me he doesn''t like me using const objects. He also doesn''t like me using interfaces. He feels that I should just make all member data public so it can be directly accessed...


balls - Maybe you should just drop C++ for a while and buff up on C. Or buy your boss a copy of "Effective C++" You you ever use the STL? I bet they love that

They apparently don''t like structures either... I was working with a guy on a LabView project, and the concept of a "typedef" was alien to him.

Magmai Kai Holmlor
- Not For Rent

Share this post


Link to post
Share on other sites
The properties that BCB uses are seemingly much easier to work with -
  
int m_Value;
void SetValue( const int );
int GetValue( void ) const;

__property Value = { read = GetValue,write = SetValue };

- makes perfect sense to me, and there''s no imports or active x needed!

Mag - didn''t bcb''s properties format come from delphi? A lot of BCB came from delphi, heck, even their win32 code base is in object pascal. I know you''ve used delphi before, which is why I ask.

But, yes, when I use the STL I basically get a "never let me see that section of code again" look. They would rather hard code a linked list traversing it manually every time they use it. I mean they won''t even use access functions! PHEW!

Null and void - I agree. Though I like c++ better, and would rather use it due to how I feel about it''s reuseablility vs c''s reuseability, I am definitely a better c programmer. I also get projects done faster when I use just plain c. That''s when I''m starting a project from scratch, though, with no reused code. Reusing my OpenGL object code will save me a few weeks worth of work on future projects, though!

Share this post


Link to post
Share on other sites
NO! The import nor ActiveX is needed (and ATL is the Active Template Library, though you can implement ActiveX controls with it, your not forced to :p)

That''s just what I was working with when I discovered that MSVC6 in fact did support property get/set tuples.

  
DWORD GetBadIdea() {return BadIdea;}
void PutBadIdea(DWORD BadIdea_) {BadIdea=BadIdea_;}
__declspec(property
(get=GetBadIdea,put=PutBadIdea)) DWORD BadIdea;

The syntax is almost the same...

And I''d bet money that the BCB''s property extension was required due to it''s Delphi roots.

What drives me absolutely nucking-futz at work, is that they used Delphi to build a very flexible program architecture - that Delphi has no-way what-so-ever of gracefully coping with. They did (and continue) to do veritable circus tricks to compile their code with Delphi. Delphi doesn’t handle dynamic arrays all that well – so they create a type array[1..10000000] as int and another type as a pointer to that type. Then declare an array pointer, and use reallocmem with a small chain of cast to allocate as much ram as they actually need. Now that’s not entirely different from the way you’d do it in C or C++, but they type definitions are kinda silly - it does bounds checking when you access the array – but with invalid bounds (1..10000000)! Maximum overhead for no benefit!
Let that be a lesson to you to mention Delphi around me :p
[end rant]

Magmai Kai Holmlor
- Not For Rent

Share this post


Link to post
Share on other sites
HAHA viva the world of lost dum f*cks! Where I work the managers are extremley nice ppl, except for the fact that they are managers in the wrong industry such as, no previous software development experience, as in never written code before... So.... they outsource some code because the team is "busy". Now suposedley, they outsourced the code to some dood who aparently has "15 years" experience... Now every time we code something, we get asked the question: "Did you guys REUSE such and suchs code?" My response to that: "No his code is crap!" Manager: "Why? He has 15 years experience" Me: "It works, doesn''t mean it is done right!" So bassically what we do, is we create custom server applications that connect to several banks around the world... All applications as a requirment must be NT services... Now the XYZ doods code is all mixed up and intertwined... Meaning he mixes C and C++, uses sometimes printfs with couts... This is do to the fact that he writes alot of code that he probably ruses, bu cutting and pasting into new applications... Also the fact that he mixed up the banking logic with the actual NT service code... etc... So my solution to his mess is rewrite a framework for services where you can subclass and overide the main NT service functions... So now my code is under review by our suposed dev lead, which is no better then me only fact that he puts up with the bullshit and am the rebelious one... bla bla bla

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!