Should we follow standards? Do you follow?
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: Should we follow standards? Do you follow?
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> . I got all the other things right
EDIT :
I found a link that confirms it
http://www.cplusplus.com/reference/iostream/
Regards
Shrek
I didnt know that <ostream> is required . But by looking at the stream hierarchy , i thought <ostream> gets automatically included when i use <iostream> . I got all the other things right
EDIT :
I found a link that confirms it
http://www.cplusplus.com/reference/iostream/
Regards
Shrek
Re: Should we follow standards? Do you follow?
Just have a look at Microsoft's 'standards'.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.
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.
Microsoft: "let everyone run after us. We'll just INNOV~1"
Re: Should we follow standards? Do you follow?
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...
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.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Should we follow standards? Do you follow?
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.B.E wrote:Just have a look at Microsoft's 'standards'.
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:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: Should we follow standards? Do you follow?
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.
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.
- Troy Martin
- 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?
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.
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?
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)
- Combuster
- 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?
tab characters are a horrible evil. They make your code appear randomly different on whatever platform you are viewing it.space tabs are a horrible evil...
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
Re: Should we follow standards? Do you follow?
? And why wouldn't we want the users of other platforms to be able to view our code according to their own preference?Combuster wrote:tab characters are a horrible evil. They make your code appear randomly different on whatever platform you are viewing it.
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.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
- Troy Martin
- 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?
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!
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?
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.
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.
Re: Should we follow standards? Do you follow?
deleted
Last edited by dude101 on Wed Apr 29, 2009 8:10 pm, edited 1 time in total.
Re: Should we follow standards? Do you follow?
Only follow standards if they dont cause any code bloat.
-
- 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?
myfile is a *pointer*, so the size on the stack is the host system's pointer width.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.
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.
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.local CPU class(passed on stack)
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.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.
Re: Should we follow standards? Do you follow?
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).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.
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.