|
> Hi, I wondered who has changed the style they use from the one they were taught.
I have...! (I recently uncovered a printout of source code to the first vertical shooter that I ever wrote in college! I scared myself with what I used to do!!! )
My coding style has morphed from:
int function ( void )
{
if ( this_variable_name!=0 )
call_this_function ();
return 0;
}
To:
int Function (void)
{
if (ThisVariableName != 0)
CallThisFunction();
return (0);
}
And finally to:
int Function( void )
{
if( iThisVariableName )
{
CallThisFunction();
}
return( 0 );
}
Guess I got smarter as I gained more experience!
-=- James.
|
|
|
|
|
i learned C from the K&R book. that used style #1. so i used that style for many years. but, eventually, i found, tried and decided that i really prefer style #2.
the official style at the job i'm at now is style #3, but i refuse to use it (along with everyone else who's been here < 3 years)
so, yes, i changed style: on my own. but i won't do it for coding standards.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I agree with your style preference, but isn't a slightly uncomfortable standard better than no standard at all? Alternatively, if everyone who's been there less than 3 years has the same preference, I would think you have a good case for banding together and proposing a change to the company standards. Maybe you could refer the more established programmers to this poll.
|
|
|
|
|
yeah right. you know that saying about old dogs and new tricks ?
b.t.w. the company in question here is *not* Smaller Animals. we do things right, there.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I'm coming to the view that enforcing coding standards just isn't that beneficial. If the standards never change, then you better have got it right the first time and what's the chance of that? If they do change, then either you've got multiple standards in legacy code or you've got to rewrite it. Neither is a good solution.
And what if you use code acquired from CodeProject, or at any rate, outside the coverage of your standards? Do you want to rewrite all that code? Even if you're just using a library/API, you're not going to wrap all the member functions/ function calls to change the style from this_is_a_function() to ThisIsAFunction() or vice versa, are you?
I do think coding style consistency is beneficial at the function level and class level, but beyond that it becomes decreasingly important. Another programmer should be able to look at a function, recognize its style and therefore find it easier to read thanks to the consistency of style. That's all that's worth aiming for.
|
|
|
|
|
> And what if you use code acquired from CodeProject, or at any rate,
> outside the coverage of your standards? Do you want to rewrite all
> that code?
If it does not follow the standard(s) that is/are in place, then yes. That is why they are called Coding Standards. Anyone that would not rewrite such code does not have real Coding Standards, just "Coding Suggestions". Standards are to be followed, no matter what. It is all part of your Software Development Process (if you have one in place).
In my experience, things like that have to be a "All or Nothing" type thing. Our developer-written-code coding standards include things like TCHAR-capable code, no #includes in header files (except StdAfx.h), and quiet builds on Warning Level 4 (with MFC/ATL/Etc. warnings #pragma-ed out). No exceptions. There are benefits to each one of them.
> Even if you're just using a library/API, you're not going to wrap all
> the member functions/ function calls to change the style from
> this_is_a_function() to ThisIsAFunction() or vice versa, are you?
Yep. In fact, we have DevStudio Add-Ins that do things like that. When we have to work with someone else's code, we need to convert it to the style that we are used to, before we try to fix it, speed it up, etc.
For example, I have written a few Add-Ins that:
o Change the spacing coventions
o Change the indenting conventions
o Change the bracing/bracketing/parens style
o Wrap "plain" quoted strings in "_T(...)" wrappers
o Change char-type-specific functions into their TCHAR counterparts
You would be amazed how many people benefit from the last two items. They are amazed when their server-side project, which now builds in Unicode, runs faster than it did before. Much is taken for granted.
> Another programmer should be able to look at a function, recognize its
> style and therefore find it easier to read thanks to the consistency of
> style.
You are correct. Any developer worth his/her salt should have no trouble adjusting/adapting to a different coding style. But in some cases, like when you are being paid by the hour to work with someone else's code, you cannot justify billing for unnecessary "adjustment time". That adjustment time gets compounded when you are dealing with lots of different code from different people.
A similar situation: you cannot bill time to a project because you needed time to "get used to" another developers code (who is on your team). Both of you should be able to glance at each other's code and know exactly what the other was thinging and/or trying to do.
Believe it or not, I *hated* the idea of a forced coding standard initially. But I now see the benefit.
Peace!
-=- James.
|
|
|
|
|
You think you've got something to complain about. The company I work for now a different coding std for several of the langs we develop in and most of the points in each one is diff. You wold think the std wouldn't change much fron c to c++ right? wrong!
|
|
|
|
|
Following the same 'convention' a professor is teaching you a language is certainly not always a good idea. I myself just finished a basic course about the Java language in an inter-university course and what the prof has given to us as code example, is really awfull (although the prof himself is a very capable and intelligent person). To give you some examples, look to the code snippet below:
private class MyHandler implements Handler
{ public void process(int position, String string)
{ printPosition(position, '>');
printString(string); }}
private String readString()
{ try
{ return in.readLine(); }
catch (IOException io)
{ return " "; }}
private void readCommand()
{ position = 0;
command = ' ';
System.out.print("command>");
try
{ String str = in.readLine();
for (int pos = 1; pos < str.length(); pos++)
{ char ch = str.charAt(pos);
if ((ch < '0') | (ch > '9'))
return;
position = 10*position + ch - '0'; }
command = str.charAt(0); }
catch (IOException io)
{ return; }}
private void printNumber(int pos, int wdt)
{ if (pos > 9)
printNumber(pos/10, wdt-1);
else
while (wdt-- > 0)
System.out.print(' ');
System.out.print(pos % 10); }
private void printPosition(int pos, char chr)
{ printNumber(pos, 6);
System.out.print(chr); }
Pls. feel free to see in an instant the 'structure' of the Java methods. I'm hardly able to read this piece of code.
So, taking this as an example is very bad, but that's my personal opinion.
Therefore, I'm not sharing the idea you have to follow the styling of professors or even some books, like Bruce Eckel's book: 'Thinking in Java'. It's a tremendously useful book for those who want to learn Java, but the coding style is also not 'the ultimate'. This is the only 'weak' point in this book.
Just to give you some examples of why you should NOT always follow books and/or people...
|
|
|
|
|
> Following the same 'convention' a professor is teaching you a language is
> certainly not always a good idea.
Very true...! One of the possible reasons for that is that during my college experience, I knew many professors/teachers/etc. that taught computer programming classes, but not a *single* one of them had real programming experience.
IMHO, you have to do it at least a little bit, before you can teach it.
Peace!
-=- James.
|
|
|
|
|
I personally prefer style #1 because of my favourite books. K&R use it, B.Stroustrup uses it, S.Lippman uses it (though not consistently), J.Richter uses it. So if it suitable for them why it shouldn't be suitable for me?
At my current job the standard is style #2, but for my home projectss I'm still using #1.
|
|
|
|
|
Well, I believe that doesn't comply with any coding standards, but it surely looks nice (and it actually works).
BTW: How do I escape smileys? I thought that inside the PRE /PRE it would not process those...? I had to insert the space between ';' and ')' at some point.
main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3]; )for(;n-->64; )
putchar(!d+++33^
l&1);}
|
|
|
|
|
#define O 0.05
#define I(c) putchar(c)
main(){
int I(int);double l[6];
char lO[5];for(*(lO+1)=
0;*(lO+1)<'2';I(0x0A),(
*(l+5))=-25*O+((*(lO+1)
)++)*O)for((*(lO+2))=0;
(*(lO+2))<'2';(*(l+4))=
-40.*O+((*(lO+2))++)*O)
{for((*(l))=(*(l+1))=0,
*(lO)=1;++*(lO)&&(((*(l
+2))=((*(l))*(*(l))))+(
(*(l+3))=((*(l+1))*(*(l
+1))))<4.);(*(l+1))=(*(
l))*(*(l+1))+(*(l+5))+(
*(l+1))*(*(l)),(*(l))=(
(*(l+2))-(*(l+3)))+(*(l
+4)));I((*(lO)?42:0x20)
);}}
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Are we going to turn this into a obfuscated code competition?
-=- James.
|
|
|
|
|
Why not if we get some nice looking and funny code out of it...?
BTW: Please note that it is on topic actually.
|
|
|
|
|
> Why not if we get some nice looking and funny code out of it...?
Because there are sites that are dedicated to this kind of thing already. We would be wasting space for no good reason.
> BTW: Please note that it is on topic actually.
Hmmm... Are you sure...? Last I checked, Ob.-ed code is not considered a "coding style". Although there are some interesting visual formats, though.
-=- James.
|
|
|
|
|
Wasting space? For no good reason? And who is deciding which reason is good - You?
"Fun code" is on topic, the pool is about the braces, and one of the choices is "Other (please demostrate)" which I did. As long as code contains any braces it is on topic. Period.
|
|
|
|
|
> Wasting space?
In some instances, yes.
> For no good reason?
Again, in some instances, yes.
> And who is deciding which reason is good - You?
No. Noone said that. Perhaps you should re-read my post, you seem to have "imagined" some text that was not there.
> "Fun code" is on topic
Not all obfuscated code is "fun code". Unless, of course, someone has decided that it is... "- You?" No, I thought not...
> the pool is about the braces, and one of the choices is
> "Other (please demostrate)" which I did.
Not all obfuscated code contains braces. (Period.)
> As long as code contains any braces it is on topic.
I never said it was not on topic. Again, please re-read my post. My concern was about turning this topic into an obfuscated code competition.
"Real Life" Tip of the month: Work brain BEFORE mouth.
"Real Life" Tip of the year: Mind the tone you take with strangers.
Lastly, note that CodeProject is a site that was designed for Win32 development. Not for obfuscated code.
Peace!
-=- James.
|
|
|
|
|
Dear James (gonna take it personally this time ),
I can see you going around and ranting at peoples posts, mostly ending with "Peace". If you have had worked brain before mounth (which is a tip of the life actually, leave a month alone) then such a suffix would not be neccessary, wouldn't it? So, since you are looking for fight, obviously, here you will get one...
As long as posts are containg an information they are not a waste of space. Give you an example. Here is the waste of space example:
>Because there are sites that are dedicated to this kind of thing already. We would be wasting space for no good reason.
To turn it into something more than ranting you could stick the URL to one or two of these sites. That would be useful...
Next, it is YOU not me who is trying to prevent peoples from posting the stuff which is certainly on topic, using an excuse of "My concern was about turning this topic into an obfuscated code competition". It did not happen, did it? It is not a competition anyway, just a samples of code. What is wrong with that?
Next, these "I never said it was not on topic." and "re-read my post". Come on, what was that "Hmmm... Are you sure...? Last I checked (snip)" all about? Yeah, I am sure that my post is on topic, and you are off topic and quite aggressive. The "Not all obfuscated code contains braces" is irrelevant - my code has braces (re-read my post shall I say...).
Next, "tip of the year" - you should re-read your post yourself and also use those tips yourself sometimes. If you have nothing to say on the thread just read the next one. You don't have to flame the posts like that all the time just because of your concerns.
>CodeProject is a site that was designed for Win32 development.
So...? Take a code and build it with VC++ - then you will be happy?
And, finally, peace!
|
|
|
|
|
> Dear James (gonna take it personally this time )
Yes... I have noticed that about certain people... I find that trying to keep it professional seems to be a waste of time, sometimes.
> I can see you going around and ranting at peoples posts,
> mostly ending with "Peace". [...]
> If you have had worked brain before mounth [...] then such a suffix would
> not be neccessary, wouldn't it?
("mounth" --> "mouth") All of my posts (should) end with "Peace!". I do not always rant. I counter when someone reacts in a negative way to, or misses something important that I wrote in, the thread. As an example, look at my first message in this thread. If you try REAL HARD, you will see something it in that should have prevented most sane people from reacting in a negative way.
> So, since you are looking for fight, obviously, here you will get one...
Most humans can see that I am not one to beat around the bush. Hence, if I wanted a fight, I would has *asked* for one. The same logic holds for unsolicited responses/flames/etc. in general.
> As long as posts are containg an information they are not a waste of space.
("an" --> "any") And you are correct... But usually, that information *strongly* relates to the topic at hand.
> To turn it into something more than ranting you could stick the URL to
> one or two of these sites. That would be useful...
Forgive me for overestimating the abilities of others to perform simple searches themselves. (I tend to overestimate the abilities of lots of people, for that I am sorry.) Here is a link (to a search engine) that should provide more than enough links for anyone.
http://search.iwon.com/commerce/multisearch.jsp?searchfor=obfuscated+code+&alias=%2Falias%2Fsearch
> Next, it is YOU not me who is trying to prevent peoples from posting the stuff
> which is certainly on topic, using an excuse of "My concern was about turning
> this topic into an obfuscated code competition". It did not happen, did it?
("peoples" --> "people") I never said that it WOULD turn into an OCC. I said that I was concerned about it. People are free to ignore my concerns, I do not force them on anyone.
I did not say "Thou shall NOT turn this thread into an OCC". Most other people know how to ignore an opinion/thought/idea/concern/etc. that they do not agree with. I would suggest anyone out there that cannot, should learn that skill .
> Yeah, I am sure that my post is on topic, [...rant deleted...]
I am glad you are sure. The Heaven's Gate leader ("Doh"?) was sure that he was taking his followers to a mothership behind a comet. But that does not mean that I should agree with him. In the same way, it also means that noone is required to agree with me.
> The "Not all obfuscated code contains braces" is irrelevant - my code has braces
Again, I never said that it did not have braces.
> (re-read my post shall I say...).
Be original.
> If you have nothing to say on the thread just read the next one.
Hmmm... I can see how others did that, too... ("Do as I say, not as I do", eh?)
> You don't have to flame the posts like that all the time just because
> of your concerns.
And others do not need to view my posts an invitation to fence with me, but they do.
> [...]and also use those tips yourself sometimes
Sage advice...
> Take a code and build it with VC++ - then you will be happy?
Not all of the code snippets in the OCCs that I have come across in the past will build under VC++ without some modification. But a nice thought, though.
>
Really...?
> And, finally, peace!
Peace!
BTW: Just in case some people have not re-read my first post on this subject, as I have suggested, there was a " " at the end of the message. Most people take that as a strong hint as to the content. Others... Well, we can see what others sometimes do...
-=- James.
|
|
|
|
|
Lastly, note that CodeProject is a site that was designed for Win32 development.
---
in that case, chris had better get rid of anything that isn't Win32 - goodbye Lounge, goodbye news stories that don't have the words MFC, Win32 or .NET in them.
and what would be wrong with having a thread turn into something off-topic? if that's what the people here want to talk about, why the hell shouldn't they talk about it? fer chrissakes...
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
>> Lastly, note that CodeProject is a site that was designed for Win32 development.
> --- in that case, chris had better get rid of anything that isn't Win32 [...]
Thank God that I did not say "CodeProject is a site that *is* designed...". Then, it would have indicated that it could not evolve into something else. But, it has yet to evolve into an Ob. Code Competition.
> and what would be wrong with having a thread turn into something off-topic?
Nothing. I said I was concerned about it, not that it should not "turn into something off-topic".
> that's what the people here want to talk about, why the hell shouldn't they
> talk about it? fer chrissakes...
People are free to do what they will. This includes misunderstand other posts, formulate responses wwhile having insufficient data, etc. I never laid down any rules. Nor do I claim to have such power.
If I did, please be so kind as to include pointers to the posts where I did. Thanks.
Peace!
-=- James.
|
|
|
|
|
>Thank God that I did not say "CodeProject is a site that *is* designed...". Then, it
>would have indicated that it could not evolve into something else.
"is", "was", we all know what you were implying.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
> "is", "was", we all know what you were implying
Since *I* am the one that typed it, and *I* was the one that knew, for sure, what *I* was trying to say, let *me* be the one to tell "all" what I was implying, if anything at all. If I would have wanted people to try to read between the lines, I would have instructed them to do so.
I do not remember doing so.
But it is nice to see that we have someone that speaks for "all".
Peace!
-=- James.
|
|
|
|
|
>But it is nice to see that we have someone that speaks for "all".
yes. it is. now get back on topic.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
My first language was Pascal. Ostensibly, Pascal taught good programming habits. Because Pascal uses 'Begin' and 'End' instead of braces, you almost have to put them on separate lines. This was one good habit I picked up and apply to C++.
Also, since AppWizard writes code with Option 2, it must be confusing for you VC++ users to have code with options 1 and 2 mixed.
It is to me a big disappointment that the Java Gods decided to use Option 1 as a standard, but what do I expect from a bunch of Unix Lusers. But it is even more of a disapointment that MS decided on Option 1 for C#. I would love to know how they justified this. VC++ and VB do not follow that style. How do they expect to get their current customers using C#? Do they really expect Java programmers to switch to C#? It will never happen.
You'd think with .NET, MS is doing everything they can to piss off their current customer base of developers.
|
|
|
|
|