attn programmers, write me a for loop and if statement.

randomlinh

Lifer
Oct 9, 1999
20,846
2
0
linh.wordpress.com
a for loop, assuming there are multiple conditions (in other words, use brackets), or an if statment.. same thing.

Why am I asking, I want to see how you guys format it. I'm arguing w/ my TA who took off 4 points for my "style." yes, it's only 4 points, but it's a principle thing to me. I don't like it when I try to explain to the grader why I do what I do, and all they do after ANYTHING I say is point to my code and say "It needs more spaces"

Here's what I'd have:

for (i = 0; i < MAX; i++)
**{
**printf(&quot;yada&quot;
**if (i < 4)
*****{
*****printf(&quot;This is stupid\n&quot;
*****printf(&quot;%d\n&quot;, i);
*****}
**}

Using C for this example, but use whatever...

 

Engine

Senior member
Oct 11, 1999
519
0
0
Indent, indent!
I look through other people's code all day, and _boy_ am I grateful that most of the people who wrote the apps I maintain had good coding style.

So.... indent! And comment! Please!

 

DAM

Diamond Member
Jan 10, 2000
6,102
1
76
for (i = 0; i < MAX; i++){
**printf(&quot;yada&quot;
**if (i < 4){
*****printf(&quot;This is stupid\n&quot;
*****printf(&quot;%d\n&quot;, i);
***}
}



thats how i do my looping, taking your example and modifying it a bit.




dam()
 

for(int i = 0; i < 10; i++)
{
____if(i == 5)
____{
________printf(&quot;Duh!&quot;
________printf(&quot;i = 5!&quot;
____}
}



 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
What dam and dwell had is perfect, I think more people would start with the { on the same like (dam), but either one looks great to me and hell to the man who would take marks off if it looks like theirs.
 

loup garou

Lifer
Feb 17, 2000
35,132
1
81
I'd do like dwell did. Every programming professor I've ever had said to put braces on separate lines, in line with each other so that when debugging you can see which pairs match up...the professor I have right now would throw his chalk at you, DAM. Programmers are weird!
 

loogie

Banned
Oct 18, 1999
2,478
0
0
Yeah..you deserved to lose those 4 points. Its not something worth arguing about...you'll just piss off the ta because by arguing about it, you are basically calling him wrong...and in this case, he wasn't. So now, you look like a smartass...I wouldn't be surprised if he graded you much more strictly now.
 

pmark

Senior member
Oct 11, 1999
921
1
81
Taking point off for style is really dick. Everbody has a different style, you just have to learn how to read the different styles. As long as it does the same thing then it should matter.

I usually the tab button for my spaces, but if it is VB i just use one space. And as for {}, it depends on how i fell that day or how the first person did it(if it isn't from scratch)
 

DAM

Diamond Member
Jan 10, 2000
6,102
1
76
ha ha screw you guys (atleast those that disagree)



for (i = 0; i < MAX; i++){
**printf(&quot;yada&quot;
**if (i < 4){
*****printf(&quot;This is stupid\n&quot;
*****printf(&quot;%d\n&quot;, i);
***}
}


if you see how it goes, you see the every &quot;}&quot; lines up with is appropriate &quot;for&quot; or &quot;if&quot; now if you are too stupid to not put a &quot;{&quot; you shouldnt be coding. the problem is not the opening one, its usually the closing one, atleast for me, specially in really conplicated loops.



example


public void menuItemSelected(MenuItem obj){
--------Graphics g = getGraphics();

--------//*****
--------// This part of the menu selects whether the user
--------// is inputting his ships or playing the game


--------if (obj == loadGame){
------------gameState = 1;
------------clear(yourFleet);
------------clear(yourShots);
------------clear(oppFleet2);
------------drawGrid(100,100,g);
------------drawGrid(400,100,g);
------------kill = 0;
------------temp0 = 0;
------------temp1 = 0;
------------temp2 = 0;
------------temp3 = 0;
------------temp4 = 0;

--------} else if(obj == startGame){
------------gameState = 2;
------------s = 0;
------------count = 1000;
--------} // end if GameState

--------//*****************************

--------if(obj == startGame1){
------------hostComp = compNumber.getText();
------------try{
----------------clientArray(hostComp, yourFleet);
------------} catch(IOException e){
----------------System.out.println(&quot;Fail&quot;
------------}
------------stringToBoolean(oppFleet);
--------} else if(obj == startGame2){
------------try{
----------------serverArray(yourFleet);
------------} catch(IOException e){
----------------System.out.println(&quot;Fail&quot;
------------}
------------stringToBoolean(oppFleet);
--------}
--------//***************************

--------//*****
--------// This part of the menu selects which of the
--------// two players is the client and which is the
--------// server.

--------if(obj == clientMI){

------------state = 1;
--------} else if(obj == serverMI){

----------- state = 2;

--------} // end if State
} // end menuItemSelected



perfect example :--)



dam()
 

denali

Golden Member
Oct 10, 1999
1,122
0
0
lnguyen,

I don't like your style hard to read. I use the same style as DAM if it's something I write by myself. Others prefer the style dwell uses. In answer to your question though unless you were given specific style guides you should not have points taken away. If I was teaching a class I would want everyone to use the same style, it make reading much easier. In the real world you will often find that you have to code in a style you don't like because it's much easier if everyone working on a project uses the same style.
 

Mark R

Diamond Member
Oct 9, 1999
8,513
16
81
Noone has mentioned the best way of reducing the confusion of curly brackets - don't use them at all!

for (i = 0; i < MAX; printf(&quot;yada&quot)
***if (i++<4)
******printf(&quot;This is stupid\n%d\n&quot;,i);

Seriously though, I would do it DAM's way.
 

randomlinh

Lifer
Oct 9, 1999
20,846
2
0
linh.wordpress.com
Here's the thing, no specifics on how to style programs. And there are about 6 different TA's that grade (hence, i'm guessing all different styles cause i was not taken off for that the first time, which is why i assumed it was OK).

The book has it dam's why, my TA for discussion has it dwells way, professor has it dwells way too.. altho he sometimes has it myway (but this is on the board writing, so who knows). And finally, the TA who graded my paper told me do do this :

if
***{
******statments;
***}

now THAT is just excessive I think.

Anyway, my reasoning for my way is that the brackets line up w/ the statements in the block. That's just the way I've been doing my code and no one complained (then again, it was HS). Argh, i'm using dwells method now tho... I refuse to do it the way they showed.. that makes it even harder to read I think... ugh..
 

greerde

Member
Jun 26, 2000
49
0
0
lnguyen,

I see you go to UMD. I'm there too. For my CMSC106 class (i'm assuming that's what you are taking), they gave us a specific style guide to use. They didn't give you guys one? I also have had many points taken off my programs for style (both 106 and 114), if you don't do it how they want....you're screwed. Anyway, try to get your hands on the style guide for your prof, and you won't lose those points anymore.
Derek
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
I can't imagine that anyone would impose their stylistic conventions on another.

The format

if (something)
****{

Is known as the GNU Style, because most (all?) of the GNU project code is written in that manner.

The proverbial format

if (something)
{

Is known as the BSD style.

Last, but not least, the format

if (something) {

Is the infamous K&amp;R style. I actually prever K&amp;R style over the BSD (and especially over the GNU style) because I think it's more elegant when written... consider:

int main(void)
{
int something = 1;
if (something) {
doSomething();
doAnotherThing();
}

if (somethingelse) {
doSomethingElse();
doYetMoreThings();
}
return 0;
}

I just think it elucidates the code...

[edit]lost my tabs... eh well[/edit]
 

br0wn

Senior member
Jun 22, 2000
572
0
0
Just follow the guidelines (might differ from one course to another)
....especially if you are in the beginning courses....it will build you up
as a good programmer.

I've taken point off from a lot of ppls because they were
not following the style guidelines (I worked as TA at one
time).

I don't take point off if you've already in advanced courses, but
if you are still learning how to program (like in beginner courses),
I'd definitely take at least 10% off for not following the guidelines.

Hey, one day when you work in industry, there will be a coding guidelines
you have to follow also.
 

randomlinh

Lifer
Oct 9, 1999
20,846
2
0
linh.wordpress.com
i think the reason i have a hard time following is i know how to program.. i just didn't exempt out of 106 (beginner) becasue they gave me a run around and i just said screw it, i'll take it as a refresher... I also shouldn't have taken it is everyone is coming to ME for debugging.... heh... but which is kind of bad... how do you tell your friend that she really should consider switching majors? ick..

anyway... as for a style guide.... no, they didn't give me one (tho, i don't remember one being mentioned.. who knows...) It's always &quot;follow good style.&quot; And shouldn't all the TA's follow that style guide? why didn't they knock me the first two times so I would know about it?

And now i have a name for what i like, GNU style, hehe.. thanks frost, didn't know that bit of info.

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |