tag:blogger.com,1999:blog-6579772240267288367.post5978106335492791965..comments2023-06-05T08:45:12.716-04:00Comments on kwblog: Coding StyleKevin Berridgehttp://www.blogger.com/profile/13759114853595462455noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-6579772240267288367.post-66272587985033303592008-08-13T17:16:00.000-04:002008-08-13T17:16:00.000-04:00Not to be a spoil sport, but coding style in this ...Not to be a spoil sport, but coding style in this context is really last century.<BR/><BR/>If you have ReSharper it is somewhat easy to keep this guideline, or some other type of formatter. Problem is, you're always going and setting this and blagh blagh blagh it requires maintenance.<BR/><BR/>As long as the developers are following good pattern development and good OOP principles the "style" is absolutely irrelevant. Once should be able to look at the structure and design of the classes and figure out what is going on.<BR/><BR/>...but I digress, too much time is spent on such things... <BR/><BR/>but hey, if the converstation entertains then I suppose the entertainment is worth it.Adronhttps://www.blogger.com/profile/00186606954315847845noreply@blogger.comtag:blogger.com,1999:blog-6579772240267288367.post-57952561015072875212008-07-18T05:13:00.000-04:002008-07-18T05:13:00.000-04:00I rarely see ?: these days. Waaaay back when I was...I rarely see ?: these days. Waaaay back when I was doing straight C programming, it was used all the time, but it seems to have fallen away with C#. To be honest I don't know for sure if C# supports it, I'm guessing it does. I always though it was a good shortcut, but I suspect today usage of it in C# code would result in a lot of maintenance developers scratching their heads :)<BR/><BR/>Oh, and the style should be:<BR/><BR/>if(_something_)<BR/>{<BR/> somethingelse;<BR/>}<BR/><BR/>Without a doubt. Spaces between the if and the opening parenthesis? No way. Visual Studio drives me nuts when it puts spaces between all your parenthesis on a line!Greg Neilsonhttps://www.blogger.com/profile/13091644084934484634noreply@blogger.comtag:blogger.com,1999:blog-6579772240267288367.post-64486435708107327132008-07-11T14:45:00.000-04:002008-07-11T14:45:00.000-04:00Truthfully, as far as if statements go, I don't ho...Truthfully, as far as if statements go, I don't hold fast to any code styles. I think I typically use if(param1,_param2), but I don't pay much attention to spaces after the if and at the ends of the parameter list.<BR/><BR/>As far as capitalization, it really depends on what language I'm using. I tend to prefer C#'s capitalization style for methods.<BR/><BR/>I really love opening curly braces on the same line as a method declaration/if/else/try/catch. It just seems to make the code more compact while still being readable. The more I think about it, I'm not sure that having an opening curly brace on its own line really provides any extra readability. I ignore the curly brace since indentation would provide the info the brace would provide.<BR/><BR/>One thing I've debated with a co-worker is the use of multiple return statements in a method. I wasn't a fan of them. I'm still not that big of a fan, but I'm starting to get used to it. I think it was only because some professor made that rule and it stuck for some reason.<BR/><BR/>The ternary operator I don't use at all. I just never remember it while I'm coding. Maybe I'll start using it more.<BR/><BR/>I did see some code today that used goto statements. Man, that was some horrible code to follow, especially since the formatting was horrible.Unknownhttps://www.blogger.com/profile/02831036920085590069noreply@blogger.comtag:blogger.com,1999:blog-6579772240267288367.post-19581363334549893622008-07-11T13:56:00.000-04:002008-07-11T13:56:00.000-04:00Oh, and about the ternary operator (?:) .... I saw...Oh, and about the ternary operator (?:) .... I saw this in a blog post the other day and really like it:<BR/><BR/>while you often "(w/s)hould" refactor the below sitauation into a inheritence hierarchy and use polymorphism to pick the correct factory method ... sometimes you still want to set a variable with a value conditionally on another value.<BR/><BR/>Instead of something like:<BR/><BR/>if(c = 1) {<BR/> var = one;<BR/>} else if(c = 2) {<BR/> var = two;<BR/>} elise if(c = 3) {<BR/> var = three;<BR/>} else {<BR/> var = four;<BR/>}<BR/><BR/>or something similar with a switch ... I did this:<BR/><BR/>var = (c == 1) ? one :<BR/> (c == 2) ? two :<BR/> (c == 3) ? three :<BR/> four;<BR/><BR/>indented correctly, it makes for a cleaner, imo, setup to show that different conditions result in different values and the default is on the end.<BR/><BR/>many may not like it, but I did.Benjamin P Leehttps://www.blogger.com/profile/15089639187841179363noreply@blogger.comtag:blogger.com,1999:blog-6579772240267288367.post-89912896878661633702008-07-11T13:50:00.000-04:002008-07-11T13:50:00.000-04:00as a up-until-recently primarially Java guy ... I ...as a up-until-recently primarially Java guy ... I always did<BR/><BR/>public void doSomething(int a) {<BR/>if(condition) {<BR/>body<BR/>}<BR/>}<BR/><BR/>** with indenting<BR/><BR/>It was hard on my last project developing both .Net and Java web service implementations where I had to switch between them going back and forth ... I ended up having to go back and uppercase my methods and whenever I did a ReSharper reformat, it always added the if_( space.<BR/><BR/>I don't mind that space, although I don't write it in in my normal flow. I am more inclined to tweak the reformating feature of the editor and use it (adjusting if necessary to fit in with the development team's common form) and use it all the time to clean stuff up after I hack at it a bit... that way I am not worrying about it while I type.<BR/><BR/>on the other hand ... the last few weeks I have been working entirely in Ruby and have a love/hate relationship with not-needing the () for method calls. For most stuff it is a lot easier and cleaner but occasionally, especially when you have calls with trailing option hashes containing other calls it can get confusing not having them in there. <BR/><BR/>Also, tracking down random names to figure out if they are a variable or method takes some getting used to but it much better than getter and setters (while I don't think they are perfect, C# properties are better imo)<BR/><BR/>I agree on the consistency but really don't like {} on new lines in C# ... I am too used to having them on the same line and having them on the next line doesn't add anything, to me, as far as readability. I use them on even one liners (b/c in refactoring I have had it bite me the butt when I changed something and didn't add them back inBenjamin P Leehttps://www.blogger.com/profile/15089639187841179363noreply@blogger.comtag:blogger.com,1999:blog-6579772240267288367.post-77697882314485746772008-07-11T13:19:00.000-04:002008-07-11T13:19:00.000-04:00I'm with the crowd on if_(something){}However i ha...I'm with the crowd on <BR/>if_(something)<BR/>{<BR/>}<BR/><BR/>However i have recently started leaving off the curly braces on single line if statements and im really starting to love the ? operator. <BR/><BR/>I also put spaces between operators and on complex ifs i favor using a lot of ()s <BR/><BR/>I never liked the curly brace on the same line as the if. i dont know why. <BR/><BR/>For methods I think i tend to do<BR/>MethodName() <BR/><BR/>As for capitalization i favor Capital First letter (is that allman style) properties and methods, camel case for variables internal to a method and parameters, and some sort of prefix for member variables usually either m or _Josh Schrammhttps://www.blogger.com/profile/04179432092617833919noreply@blogger.comtag:blogger.com,1999:blog-6579772240267288367.post-53589864659840472522008-07-11T13:13:00.000-04:002008-07-11T13:13:00.000-04:00I prefer ”if_(condition)”. Like you, I did use to ...I prefer ”if_(condition)”. Like you, I did use to add extra spaces within the parenthesis (in C/C++), but I stopped doing it when I started developing in C#, partly because Microsoft didn’t do it in its C# sources, partly because it didn’t really enhance readability. However, I <STRONG>need</STRONG> to use spaces between operators, or else I’ll go mad. :-)<BR/><BR/>Generally, I always try to follow the style that is the most common on the platform. Hence I write<BR/><BR/> public void DoSomething()<BR/> {<BR/> ...<BR/> }<BR/><BR/>in C#, but<BR/><BR/> public void doSomething() {<BR/> ...<BR/> }<BR/><BR/>in Java. I don’t believe pascal casing and the Allman style is any more readable than camel casing and the K&R style, but I very much do believe it’s important to <STRONG>be consistent</STRONG> and to <STRONG>go with the flow</STRONG>. I also know that Microsoft did invest quite a bit in creating the .NET Framework Design Guidelines, and I don’t think there are many well thought-out reasons to go against it when coding in C#.Kallehttps://www.blogger.com/profile/14673030877301419801noreply@blogger.com