OPC (Other People's Code)

  • (6 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6

84 Replies - 10138 Views - Last Post: 23 October 2012 - 07:36 AM

#46 s3thst4  Icon User is offline

  • a * a = (b * b) + (c * c) - 2(b)(c)cos(A)
  • member icon

Reputation: 10
  • View blog
  • Posts: 587
  • Joined: 20-November 08

Re: OPC (Other People's Code)

Posted 10 February 2009 - 12:25 PM

Most of the things that bother me were mentioned in the first post, when people don't indent it all perfectly, and when there's no whitespace after a comma.
But one of the biggest is when my friend codes, he presses enter before each method he creates, and Idk, it bothers me.
Was This Post Helpful? 0
  • +
  • -

#47 LaFayette  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 326
  • Joined: 24-November 08

Re: OPC (Other People's Code)

Posted 10 February 2009 - 02:14 PM

Quote

no reason to have some variable sitting around in memory somewhere if it isn't going to be used. waste of space. (it being the whole for loop thing up about 5 posts)


Won't make any difference memory wise. Memory isn't released just because you get out of scope, it's released when the method/function terminates.

Limiting the scope is a good enough reason.
Was This Post Helpful? 0
  • +
  • -

#48 fuzzylunkinz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 185
  • Joined: 11-November 08

Re: OPC (Other People's Code)

Posted 10 February 2009 - 06:09 PM

Someone I help daily managed to get some code like the following . . . using the VS2008 IDE. Actually, he does it every day.

do
{  if(aa)
    { // Use variable ij
}}while(fx);



Just look at those variable names -.-
Was This Post Helpful? 0
  • +
  • -

#49 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: OPC (Other People's Code)

Posted 10 February 2009 - 06:28 PM

I'm looking more at the end if brace on the same line as the while loop YUCK!
Was This Post Helpful? 0
  • +
  • -

#50 fuzzylunkinz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 185
  • Joined: 11-November 08

Re: OPC (Other People's Code)

Posted 10 February 2009 - 06:46 PM

Putting stuff on same line as the starting brace, too!
Was This Post Helpful? 0
  • +
  • -

#51 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: OPC (Other People's Code)

Posted 10 February 2009 - 06:49 PM

That is absolutely horrifying. Why do people do that?
Was This Post Helpful? 0
  • +
  • -

#52 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,110
  • Joined: 07-September 06

Re: OPC (Other People's Code)

Posted 10 February 2009 - 07:10 PM

I have my own (well kinda, it is different from many standard coding styles, but still pretty standard in total) style. It looks like so:

// normal class
class className{
  //normally an indent if in a compiler, otherwise I swap it for 2 spaces
private:
  // variables
public:
  className(){
    // does stuff
  }
  ~className(void){
    // does stuff
  }
};

// for templated classes
templace<class T> class className{
  //normally an indent if in a compiler, otherwise I swap it for 2 spaces
private:
  // variables
public:
  className(){
    // does stuff
  }
  ~className(void){
    // does stuff
  }
};

int main(){
  // does stuff
  return 0;
}


// variable declarations
Type varName = value;
varName++;
varName += value;
varName = " "+value+" test";

// if statements
int i = 0;
if(i == 5){
  // does stuff
}
else{
  // does something else
}

// loops
while(i != 10){
  i++;
  // does stuff
}
for(int b = 0; b<10; b++){
  // does stuff
}

// output statements
cout << "Stuff" << endl;




And so on. It is pretty much standard, I just don't follow the thing that "if an if/else statement is only 1 line don't worry about using brackets ({, }) around it" I can't stand not knowing exactly everything that is supposed to be looked at in a statement.
Was This Post Helpful? 0
  • +
  • -

#53 fuzzylunkinz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 185
  • Joined: 11-November 08

Re: OPC (Other People's Code)

Posted 10 February 2009 - 07:35 PM

I would also like to point out that if you are anal-retentive about coding style, code in Python :cool:.

This post has been edited by fuzzylunkinz: 10 February 2009 - 07:37 PM

Was This Post Helpful? 0
  • +
  • -

#54 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,595
  • Joined: 16-October 07

Re: OPC (Other People's Code)

Posted 10 February 2009 - 07:52 PM

View Postfuzzylunkinz, on 10 Feb, 2009 - 08:35 PM, said:

I would also like to point out that if you are anal-retentive about coding style, code in Python :cool:.


Not anal enough. To tab, or not to tab. And indent size... It's like a holy war. ;)

Seriously, no language is free of coding style; and that style choice will bug the hell out of someone. You can't even get away from it at machine code level; how you shift registers and organize blocks will become an issue even though each operation is fixed.
Was This Post Helpful? 0
  • +
  • -

#55 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: OPC (Other People's Code)

Posted 11 February 2009 - 08:04 AM

View Postno2pencil, on 9 Feb, 2009 - 10:08 PM, said:

View PostTom9729, on 9 Feb, 2009 - 09:51 PM, said:

* When someone declares and defines a variable on the same line (all the time).

I find this interesting. One of my pet peeves is when a variable is declared in the for loop line.

Which would you prefer?

int i=0;
for(i;i<10;i++) 



or

int i;
for(i=0;i<10;i++)



or


for(int i=0;i<10;i++)



This one:

int i;
for(i=0;i<10;i++)



Because it only needs to be declared once, and sometimes I reuse the counter in another for loop. I don't want a bunch of different counter variables if I can get away with only using one. It's less confusing for me and less messy that way.

I don't really have any peeves about other people's code. I'm usually too busy trying to get my own code written properly.

About the 'too many comments' issue. I agree, you don't need comments for every little thing. I prefer to only use them if I think I might forget (or someone else may not be able to tell easily) why I wrote it the way I did. However, I think instructors prefer their students to comment the code so they know the student knows what they are doing, and why. I over-comment my homework code, which bugs me.

:rolleyes:

//p.s. I find that no matter what I do, it's going to bug someone.
Was This Post Helpful? 0
  • +
  • -

#56 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Re: OPC (Other People's Code)

Posted 11 February 2009 - 01:24 PM

IMO "too many comments" is not a bad thing if they are good comments.

This is an example of what I think is a bad comment.
// This is an array list.
ArrayList array = new ArrayList();


Was This Post Helpful? 0
  • +
  • -

#57 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: OPC (Other People's Code)

Posted 11 February 2009 - 01:52 PM

:lol:


//Variable declaration
int myVar = 2;


Was This Post Helpful? 0
  • +
  • -

#58 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2586
  • View blog
  • Posts: 15,618
  • Joined: 24-September 08

Re: OPC (Other People's Code)

Posted 11 February 2009 - 03:20 PM

No documentation.
Was This Post Helpful? 0
  • +
  • -

#59 5ubw0r1d  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 78
  • Joined: 18-May 07

Re: OPC (Other People's Code)

Posted 11 February 2009 - 06:19 PM

People who feel the need to write

var i = 0;

i = i + 1;




instead of

var i = 0;

i += 1;



or even worse still, people who write
var i = 0;

i += 1; // same as i = i + 1


This post has been edited by 5ubw0r1d: 11 February 2009 - 06:21 PM

Was This Post Helpful? 0
  • +
  • -

#60 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,897
  • Joined: 10-May 07

Re: OPC (Other People's Code)

Posted 11 February 2009 - 07:13 PM

Attached Image
Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • 6