inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Nov 19, 2009 21:23:07 GMT -8
So currently learning Java. It's annoying when you're given sample code in a completely different layout to how I normally code... really annoying. So this got me thinking, what styles do the coders over here have? For example do you: if(x == 1){ /* Do some stuff */ }or... if(x == 1) { /* Do some stuff */ }or even... if(x==1){ /* Do some stuff */ }As Charles know's I'm one for spaces... Personally I use the top layout, however much of the example code which we have to edit is coded in the 3rd type, with no spacing whatsoever, so kinda annoying. Also, are you a 'tab' guy, or a '3 space' kinda person? So show! Perhaps show more code 'cause then it'll show it better!
|
|
inherit
76880
0
Sept 1, 2012 21:33:51 GMT -8
(¯`•Stormraven•._)
6,883
April 2006
stormraven
|
Post by (¯`•Stormraven•._) on Nov 19, 2009 22:14:21 GMT -8
First option, im one for spacing and tabbing too.
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 19, 2009 22:30:25 GMT -8
I use the first for Javascript, but I use the second for everything else since it's required in school. I actually like it more now since it looks better when you are creating classes that have a lot of member functions. I love tabs as well, and I think that you should always use them so it's easier to read.
I dislike it when programmers (usually novice programmers) try to compact their code as much as possible so it looks complex and hard. I admit I did that when I just started out, but it shouldn't be that way, especially when you are working with other people. Space everything out so it's easy for others to read and comprehend quickly.
According to my professor, simply using the conditional operator (condition ? true : false) will get you fired from a lot of companies. You always have to type it out.
if(condition) { // Code. } else { // Code }
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Nov 20, 2009 7:08:27 GMT -8
I use the first for Javascript, but I use the second for everything else since it's required in school. I actually like it more now since it looks better when you are creating classes that have a lot of member functions. I love tabs as well, and I think that you should always use them so it's easier to read. I dislike it when programmers (usually novice programmers) try to compact their code as much as possible so it looks complex and hard. I admit I did that when I just started out, but it shouldn't be that way, especially when you are working with other people. Space everything out so it's easy for others to read and comprehend quickly. According to my professor, simply using the conditional operator (condition ? true : false) will get you fired from a lot of companies. You always have to type it out. if(condition) { // Code. } else { // Code }I use ternary operators all the time in my coding. Never been told it'll get me kicked out or anything!
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 20, 2009 7:22:37 GMT -8
I use tabs, as it's the most logical, since even NOTEPAD (let alone all other program editors) allows you to change the spacing of tabs. Not to mention shift-tab making life easier for huge code edits. I see no reason whatsoever one should use spaces over tabs.
Also, I do the line-break version. if (condition) { stuff(); }
IDK why. It just looks better, imo. Makes finding things easier.
Sounds like BS to me. I do that all the time, because it's the most efficient way.
|
|
inherit
17569
0
Aug 14, 2023 13:11:03 GMT -8
frufru
11,774
December 2003
frufru
|
Post by frufru on Nov 20, 2009 7:50:05 GMT -8
My stuff tend to look more like the first one. I try to keep stuff more spaced out because it's easier to read. My habit is also to keep the { on the same line as the condition. Perhaps it's out of adaptation from using vb where it's If condition Then stuff End If And yeah, I tab when I can. I've also never heard of companies having problems with using the ternary operator either. I've used it on my work terms coding in Java and C# without problems. It's quite efficient. By the way, in MS Visual Studio 2008, if you type out a conditional expression that can be replaced with a ternary operator, it will actually highlight it and give you an option to have it convert the expression to an expression using a ternary operator. Actually that might have been done with ReSharper but oh well
|
|
inherit
54640
0
Jul 2, 2019 10:52:15 GMT -8
Phrate
It's been 9 years!
1,297
August 2005
ghotherkill
|
Post by Phrate on Nov 20, 2009 8:01:09 GMT -8
Eh, I usually do my stuff as follows: if(condition || this && other) { // tab // do code } else { // blah } And, on some occasions, I pad the code inside of the if's: if(condition) { // // tab // do code // } (Without the top and bottom "//"'s
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 20, 2009 8:43:22 GMT -8
I use ternary operators all the time in my coding. Never been told it'll get me kicked out or anything! I do as well, that's just what he told us. It really depends who you are working for and what type of project it is. I see no problem with it because it's not hard to read at all unless you are using more than one in one line. Sounds like BS to me. I do that all the time, because it's the most efficient way. It depends who you are working for, but I really doubt that there are a lot of companies that are like that to be honest. I've also never heard of companies having problems with using the ternary operator either. I've used it on my work terms coding in Java and C# without problems. It's quite efficient. I don't see why they would be against it, he just told us that some companies will get pissed if you use it.
|
|
jadw2k9
inherit
-3799062
0
Dec 2, 2024 10:29:40 GMT -8
jadw2k9
0
January 1970
GUEST
|
Post by jadw2k9 on Nov 20, 2009 14:00:58 GMT -8
So currently learning Java. It's annoying when you're given sample code in a completely different layout to how I normally code... really annoying. So this got me thinking, what styles do the coders over here have? For example do you: if(x == 1){ /* Do some stuff */ }or... if(x == 1) { /* Do some stuff */ }or even... if(x==1){ /* Do some stuff */ }As Charles know's I'm one for spaces... Personally I use the top layout, however much of the example code which we have to edit is coded in the 3rd type, with no spacing whatsoever, so kinda annoying. Also, are you a 'tab' guy, or a '3 space' kinda person? So show! Perhaps show more code 'cause then it'll show it better! I hate it when people use seperate lines for brackets. I try to condense it so I can see more on fewer lines.
int a = 1; int b = 20; int i;
for (i=a; i<=b; i++) { if (i == b) { system.out.println(i+'.'); } else { system.out.print(i+', '); } }
Then again I also hate it when people put lots of statements, conditionals, fors, etc all line after line and leave no blank lines (i.e. paragraphs) to make it easier to see what's going on. I put relevant lines of code together and if I have, say, four statements and then an if, I'll put a blank line between the fourth statement and the if part.
|
|
inherit
50924
0
Feb 28, 2021 14:59:32 GMT -8
BFD
Last place must get awful crowded at the Nice Guy Olympics
1,708
July 2005
dwinman164
|
Post by BFD on Nov 20, 2009 14:02:16 GMT -8
Sounds like BS to me. I do that all the time, because it's the most efficient way. Is it really more efficient? Or is it an assumption based on writing "less code"?
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Nov 20, 2009 15:09:26 GMT -8
Sounds like BS to me. I do that all the time, because it's the most efficient way. Is it really more efficient? Or is it an assumption based on writing "less code"? If I remember rightly, the way it's parsed is different to the standard if statement. It's interesting when you combine 3 or 4 ternary operators! ^_^ @ me - you don't put spaces between the attributes of the for statement? I always have to put a space after the "=" and after the ; before the < etc...
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 20, 2009 23:14:00 GMT -8
Haha. I do that all the time, but I also tend to use multiple lines if it gets too long, so that it still looks like an if() statement but without the unnecessary parsing
y = ( x == 1 ? 10 : ( x == 2 ? 12 : ( x == 3 ? 15 : 20 ) ) );
Or summat. Obviously not that exact thing, 'cause that could be epic simplified with an Array, but that's just an example of a layout of a whored-inline-if-statement-compilation.
It uses less variables, therefore it uses less memory, therefore it's more efficient.
For example: $test = 'win'; if ($test == 'win') $output = 'you rock'; else $output = 'you suck'; echo $output;
This could be simplified to: $test = 'win'; echo ($test == 'win' ? 'you rock' : 'you suck'); $output never has to be defined, so it takes up no memory at all (except for $test).
|
|
inherit
12045
0
Nov 19, 2012 14:52:05 GMT -8
Renegade
As unique as mice pudding milkshake
40,557
August 2003
renegade
|
Post by Renegade on Nov 21, 2009 15:21:10 GMT -8
i do all my coding on one line, and add line breaks occasionally if i need to go back and edit stuff
|
|
inherit
72731
0
Oct 6, 2012 2:03:55 GMT -8
ŠΗäMΘηΘ
4,135
February 2006
smwt
|
Post by ŠΗäMΘηΘ on Nov 28, 2009 12:11:16 GMT -8
#1 with tabs for source code and 3 spaces for anything sent back to the browser.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 28, 2009 16:38:42 GMT -8
I like the first one, but my opinion is useless lol
|
|