I prefer the first way too, and that's now most of the code I see is written. But really both are perfectly readable. It's just a case of getting used to the other one.
And if you can't or won't, you can configure a good IDE to tidy up formatting at a keystroke.
24 Replies - 1048 Views - Last Post: 30 May 2012 - 09:59 PM
#17
Re: Improvements in my code.
Posted 30 May 2012 - 05:02 AM
It's not that I can't read it or anything, I just hate the look of it.
#18
Re: Improvements in my code.
Posted 30 May 2012 - 10:50 AM
Maybe you hate the look of it because you can read it.
Perhaps it's not as "super nerd" as you'd expected. The programming world has been demystified and it's not just the stuff of cliché, "Zoom! Enhance!"-type crime shows anymore.
"Don't worry, boss! I can hack into this guy's computer because the script says so."
Perhaps it's not as "super nerd" as you'd expected. The programming world has been demystified and it's not just the stuff of cliché, "Zoom! Enhance!"-type crime shows anymore.
"Don't worry, boss! I can hack into this guy's computer because the script says so."
This post has been edited by Gungnir: 30 May 2012 - 10:50 AM
#19
Re: Improvements in my code.
Posted 30 May 2012 - 11:15 AM
Quote
I'm not looking forward to finishing University and getting into the programming work force.
If you aren't looking forward to it, then why are you doing it?
To be honest the position of your curly brackets are going to be the least of your worries. Spend a couple of days with either and you'll be wondering why anyone would every want to use the other.
#20
Re: Improvements in my code.
Posted 30 May 2012 - 11:20 AM
cfoley, on 30 May 2012 - 04:51 AM, said:
Something in Java that has always irritated me is how to properly write a setter. I think an underscore convention could help but it would never be accepted. Say we have a private int size;
// single letter variable names are bad style
public void setSize(int s) {
size = s;
}
This is the canonical form, and there's a good reason for it. It's because when this method shows up in javadoc, it's with the actual parameter name as it appears in the method declaration, and you'd like that to be the name of the parameter that's being set.
You don't want it to show up with any weird non-alpha characters or hungarian crap, you just want "size", so use that.
#21
Re: Improvements in my code.
Posted 30 May 2012 - 11:32 AM
ILoveJava, on 30 May 2012 - 05:23 AM, said:
Personally, I'm not looking forward to finishing University and getting into the programming work force. When I started programming, my brackets, always follow the method like this
But 98% of programmers I have met/spoken to, will do it on the next line like this
Am I the only one who doesn't like the look of this? As much as programming is all about readability and actual function, I personally like the aesthetics of the source code.
If I'm lurking the board, and there is an extremely sloppy source code posted, even if I don't know how to fix the problem, I will take the code, post it into my IDE, and clean it up. And again, am I the only one who does this? Haha.
public static void main(String[] args) {
}
But 98% of programmers I have met/spoken to, will do it on the next line like this
public static void main(String[] args)
{
}
Am I the only one who doesn't like the look of this? As much as programming is all about readability and actual function, I personally like the aesthetics of the source code.
If I'm lurking the board, and there is an extremely sloppy source code posted, even if I don't know how to fix the problem, I will take the code, post it into my IDE, and clean it up. And again, am I the only one who does this? Haha.
There are many long and tedious arguments to have about brace styles. The arguments basically come down to saving vertical space (K&R style, traditionally used in printed books where vertical space is expensive) and aligning braces to make block structure stand out (Allman style, traditionally used on CRTs and other terminals, where vertical space is free).
If you're using an IDE, it's not an issue. Just set your IDE to display the way you like it and away you go.
#22
Re: Improvements in my code.
Posted 30 May 2012 - 01:05 PM
ILoveJava, on 30 May 2012 - 06:23 AM, said:
Personally, I'm not looking forward to finishing University and getting into the programming work force. When I started programming, my brackets, always follow the method like this
But 98% of programmers I have met/spoken to, will do it on the next line like this
public static void main(String[] args) {
}
But 98% of programmers I have met/spoken to, will do it on the next line like this
public static void main(String[] args)
{
}
That's again a pure convention between C/C++ and Java. Look at the API, it is all the Java way
When I first started with Java I really hated the Java way... but really hated it thinking nobody will ever make me change my way of doing things
Now, I love it, and when I program in C at the office I have to force myself to use the old C way.
Quote
But 98% of programmers I have met/spoken to, will do it on the next line like this
Old C++ programmers ?
#24
Re: Improvements in my code.
Posted 30 May 2012 - 09:56 PM
I picked the convention up with C++ and it carried over.
With one exception(pun intended)
I find that changing coding convention mid-program is the lesser of two evils. However, if the exception itself is used in some way then I don't do that.
With one exception(pun intended)
//Sometimes I'll write a try-catch-finally block the other way
//When the exception isn't explicitly handled.
try{
}catch(Exception e){
}
try
{
}
catch(Exception e)
{
//Because this is empty and ugly
}
//and I dislike the style of:
...
catch(Exception e){}
I find that changing coding convention mid-program is the lesser of two evils. However, if the exception itself is used in some way then I don't do that.
#25
Re: Improvements in my code.
Posted 30 May 2012 - 09:59 PM
I suspect it's more to do with use versus non-use of IDEs for development. If you're using an IDE, the machine does more to keep track of block structure for you, so you don't have to line up your braces. If you're doing it in a text editor - or if you learned programming in a text editor - then you need to have that visual cue to help you line up complex nesting correctly.
Or that's a theory, anyway...
Or that's a theory, anyway...
|
|

New Topic/Question
Reply





MultiQuote



|