Should we follow standards? Do you follow?

Programming, for all ages and all languages.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Should we follow standards? Do you follow?

Post 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
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Re: Should we follow standards? Do you follow?

Post 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.
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Should we follow standards? Do you follow?

Post 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...
Every good solution is obvious once you've found it.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Should we follow standards? Do you follow?

Post 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.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Should we follow standards? Do you follow?

Post 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.
My OS is Perception.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Should we follow standards? Do you follow?

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Should we follow standards? Do you follow?

Post 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)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Should we follow standards? Do you follow?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Re: Should we follow standards? Do you follow?

Post 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?
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Should we follow standards? Do you follow?

Post 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!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Should we follow standards? Do you follow?

Post 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.
Every good solution is obvious once you've found it.
dude101
Member
Member
Posts: 56
Joined: Thu Apr 09, 2009 10:26 pm

Re: Should we follow standards? Do you follow?

Post by dude101 »

deleted
Last edited by dude101 on Wed Apr 29, 2009 8:10 pm, edited 1 time in total.
dude101
Member
Member
Posts: 56
Joined: Thu Apr 09, 2009 10:26 pm

Re: Should we follow standards? Do you follow?

Post by dude101 »

Only follow standards if they dont cause any code bloat.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Should we follow standards? Do you follow?

Post 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.
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Should we follow standards? Do you follow?

Post 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.
Post Reply