Page 3 of 4

Re: Should we follow standards? Do you follow?

Posted: Thu Feb 19, 2009 6:38 pm
by DeletedAccount
Hey,
I didnt know that <ostream> is required . But by looking at the stream hierarchy , i thought <ostream> gets automatically included when i use <iostream> . :mrgreen: I got all the other things right :mrgreen:


EDIT :
I found a link that confirms it :)
http://www.cplusplus.com/reference/iostream/
Regards
Shrek

Re: Should we follow standards? Do you follow?

Posted: Fri Feb 20, 2009 3:59 am
by B.E
Solar wrote: And because they were good, they were accepted into the standard (like // was). Until it's in the standard, using it limits you to a specific toolchain, probably even a specific version of that toolchain. Toolchains change, and suddenly your code doesn't work anymore. (It's not the toolchain, it's your code, which was broken all the time, only now the toolchain doesn't let you take that shortcut anymore.)

If enough coders are negligent enough, such an illegal shortcut becomes a "historic legacy", and time, effort, and money is wasted because toolchains have to maintain compatibility with the bad practices of yesterday. Time, effort, and money that could have been invested in improving those toolchains instead.

Not even talking about the pains you have brought onto those who had to think around your shortcuts. Chances are, a smart piece of non-standard code that saved you a minute in coding will cost others many times as much in productivity as they have to think around or refactor your shortcut.
Just have a look at Microsoft's 'standards'.

I absolutely agree with you, I am working on a project, in which I am replacing an old system. The old system is not documented or in any way written following standards. The project is an absolute nightmare. So speaking from experience, please do not, I'll repeat, do not write applications using non standard features, or at least please please please document it.

Re: Should we follow standards? Do you follow?

Posted: Fri Feb 20, 2009 5:41 am
by Solar
Point in case: I just spent half a day figuring out what a specific class in the company code actually did. (No comments at all.) Turns out it is some kind of memory manager, which could be replaced with auto_ptr<> or shared_ptr<>. It should be replaced, actually, since functions like alloc_char(), alloc_int(), clear() (huh?) and rewind() (double-huh?), throwing runtime_exception on error (instead of bad_alloc) - that's not nice to maintain.

Problem is, usage is spread all over the code base, so I am stuck with having to support a "memory manager" that's awkward to use, and a heap crash waiting to happen...

Re: Should we follow standards? Do you follow?

Posted: Fri Feb 20, 2009 10:46 am
by Colonel Kernel
B.E wrote:Just have a look at Microsoft's 'standards'.
Not a problem if you only develop on Microsoft's platforms. ;) I don't recall MS ever claiming to make cross-platform development easy.... Come to think of it, I don't remember any vendor making that promise.

It goes back to what I said before... If you want portable code, use a portable compiler (if at all possible). After working with and on various standards for almost ten years, I've come to the conclusion that specs are inherently ambiguous. The only practical way to achieve portability/interoperability/whatever is to follow a reference implementation.

Re: Should we follow standards? Do you follow?

Posted: Fri Feb 20, 2009 7:08 pm
by AndrewAPrice
I rarely use 'using' in C++.

I just get's confusing when you have conflicts:
std::string vs my framework's string
std::vector vs my framework's Vector2D/Vector3D
std::map vs my game's map/level
etc

It doesn't bother me adding a "std::" when explicitly needed. The same with working with frameworks (ogre::, irr::, mgf::, etc).

My reasoning is because it makes thing easier to find what framework something belongs to, and 90%+ of my code ends up being logic so it doesn't look messy or anything.

Re: Should we follow standards? Do you follow?

Posted: Sat Feb 21, 2009 10:42 pm
by Troy Martin
I try to follow C99. ( // comments, etc.)

For tabs, I normally go with whatever my IDE does unless I'm adding to code that already has a predefined way of tabbing. For example, TBOS is tabbed with the tab key since that how it looks best in Visual Studio, but I use 4 spaces in Dev-C++ since that's what it puts in when you press the tab key.

Re: Should we follow standards? Do you follow?

Posted: Sat Feb 21, 2009 11:06 pm
by earlz
Troy Martin wrote:I try to follow C99. ( // comments, etc.)

For tabs, I normally go with whatever my IDE does unless I'm adding to code that already has a predefined way of tabbing. For example, TBOS is tabbed with the tab key since that how it looks best in Visual Studio, but I use 4 spaces in Dev-C++ since that's what it puts in when you press the tab key.

space tabs are a horrible evil...

try editing in your visual studio and then in Dev-C++(the same file).. every other line has a different indent style and crap.. .its just best to use tab tabs and let the person reading hte code configure their editor for how many spaces each tab character represents...(converting tabs isn't fun, btw)

Re: Should we follow standards? Do you follow?

Posted: Sun Feb 22, 2009 8:09 am
by Combuster
space tabs are a horrible evil...
tab characters are a horrible evil. They make your code appear randomly different on whatever platform you are viewing it.

Re: Should we follow standards? Do you follow?

Posted: Sun Feb 22, 2009 9:44 am
by madeofstaples
Combuster wrote:tab characters are a horrible evil. They make your code appear randomly different on whatever platform you are viewing it.
? And why wouldn't we want the users of other platforms to be able to view our code according to their own preference?

Re: Should we follow standards? Do you follow?

Posted: Sun Feb 22, 2009 11:02 am
by Troy Martin
Woot, holy war!

And converting tabs is easy in visual studio: just select all of the code that has different tabs, do shift+tab, and then with it selected again, hit tab. Done!

Re: Should we follow standards? Do you follow?

Posted: Mon Feb 23, 2009 12:18 am
by Solar
Space tabs are the only way to make your code look as intended.

Also, it's the one setting that can be easily checked for automatically on check-in. (Repositories I have set up simply disallow tabs in non-Makefile files.)

If you've ever had to deal with a file that randomly mixed space-tabs with tab-tabs, you'll know what I mean.

Re: Should we follow standards? Do you follow?

Posted: Tue Apr 28, 2009 9:03 pm
by dude101
deleted

Re: Should we follow standards? Do you follow?

Posted: Tue Apr 28, 2009 9:04 pm
by dude101
Only follow standards if they dont cause any code bloat.

Re: Should we follow standards? Do you follow?

Posted: Wed Apr 29, 2009 12:51 am
by pcmattman
The error of that code though is that now to use myfile, you must pass it to every function. A few extra pushes per function in a loop though can have a rather big performance penalty.
myfile is a *pointer*, so the size on the stack is the host system's pointer width.

If it wasn't a pointer, then yes, you would be passing it in full along the stack. That's what passing by reference is for.
local CPU class(passed on stack)
If you knew your language you would've passed by reference rather than passing the object on the stack. Or you would've used pointers.
It is for this reason, I no longer use C++... C++ is built for people wanting fastly developed code, not necessarily the fastest code, C is built to work anywhere and as fast as you would like to optimize it for.
It all comes down to knowledge and personal preference. It would seem to me you prefer C. I prefer C++. We can agree to disagree, but please don't point out "problems" with it that come down to faulty coding.

Re: Should we follow standards? Do you follow?

Posted: Wed Apr 29, 2009 3:14 am
by skyking
skwo wrote:Hello everybody!
I would like to know how many of you, from the people who write in clear C, follow standards? I mean not using // as comments, declaring variable only in the beginning of the block, and etc?
How do you think, follow ANSI standards considered as "old fashion"?
I always try to declare variable in the beginning of the block, and try to follow the standards as much as I can, but I discovered that GCC don't pay attention to, and while I tried to compile my code on MVC, I got dozed of errors, and it was annoying to fix them.
Although GCC does accept some extensions to the C standard, MVC does not implement the standard very well. Also note that contrary to what some ignorant programmers may think, only that it passes compilation with a particular C compiler does not mean that it is standard compliant (and compilers that rejects the code are not necessarily broken). ISO C does allow // as comment, so I'd say go for it - old obsolete standard's should be regarded as such (there may be reasons you need to follow them anyway though).

I think you should have a valid reason to depart from the standard and use a non-standard extension, and preferably in that case isolate the non-standard code from the standard so you can keep the code reasonably portable.