coding-style

F# coding style and standard

While there is no One True Correct Style, some points of general agreement exist in the C# community regarding coding standard / style; usually, they are variations of the .NET Framework Design Guidelines. When you look into F#, though, the standard is visibly different from what is considered normal in C#. As an example, the function...

returning params from a method

Hi, I was wondering which is better style to return a parameter from a method: 1. if (someBooleanIsTrue) { someTypeList = getTypeInstance(param1, param2); } else if (anotherBooleanIsTrue) { someTypeList = getTypeInstanceSecondMethod(param1, param2); } return someTypeList; 2. List<SomeTy...

Accessing NSManagedObject fields with KVC/valueForKey vs properties - which is better?

Writing my first app with CoreData. The book I'm using to guide me has code like this: // 'Person' is my managed object class Person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:self.managedObjectContext]; [newPerson setValue:nameField.text forKey:@"name"]; The book says that...

C++ pass by reference

I've recently (4 days) started to learn C++ coming from C / Java background. In order to learn a new language I ussualy start by re-implementing different classical algorithms, as language specific as I can. I've come to this code, its a DFS - Depth First Search in an unoriented graph. Still from what I read it's best to pass parameters...

StyleCop happy creation of Xml using XDocument / XElement / XAttribute

I like to create xml using the following formatting: XDocument xml = new XDocument( new XElement("Root", new XElement("A", new XAttribute("X", xValue), new XAttribute("Y", yValue)), new XElement("B", new XAttribute("Z", zValue)), new XElement("C"))); It seems easy to read and kinda flows...

Consistenty header file names between C++ libraries

In my project I use two libraries, v8 and boost. Boost uses the .hpp extension for its headers, while v8 uses the .h extension for its headers. In the end of day, my source code starts like that: #include "v8.h" #include "boost/filesystem.hpp" ... In other question I asked about this subject, the general answer was that it is okay, b...

Using jQuerys document.Ready function to attach events to elements

Normal style <a href="#" id="myLink" onclick="myFunc();">click me</a> function myFunc() { alert('hello!'); } jQuery style <a href="#" id="myLink">click me</a> $(document).ready(function() { $("#myLink").click(function() { alert('hello!'); }); }); I've just started using jQuery, but I'm wondering what the diffe...

How to make sure that my SQL code is not a scary mess

SQL seems to be the most neglected language when it comes to formatting nicely and readably... And as SQL statements can be incredibly detailed and complex, it makes it extremely hard to work with. But I find that when I try to format my SQL code in the best way possible I'm sometimes unsure of how to do it. I know the standards for Java...

Need inspiration for naming classes and methods.

Possible Duplicates: Anyone else find naming classes and methods one of the most difficult part in programming? Whats the best approach to naming classes? Finding appropriate abstraction names can sometime be time-consuming, especially if your mother tongue is not english. I was wondering if there exists somewhere some sort...

Using true and false as the expressions in a conditional operation

I'm maintaining some code and have found the following pattern a lot: var isMale = (row["Gender"].ToString() == "M") ? true : false; instead of this: var isMale = (row["Gender"].ToString() == "M"); Is there any reason why anyone would do this? Does anyone think the former is more readable or clearer? Is there some sort of old C "go...

Web Development

Hi, Lets take a website project with a number of team members and it has a number of features. During the development, Is it better for same guy to do one complete feature(DB,Application Logic,Frontend(Javascript,HTML,CSS etc)) or Is it better for the different guy to do the Application Logic and Frontend. In most of the cases, DB is ...

How does HTML deal with white space in the markup?

I am not talking about white space in the content, but the code itself. I had a bunch of validation errors in my HTML and discovered it was because I was missing a space in my markup - <td class="col_title"colspan="2"> Line 1, Column 80: attributes construct error Line 1, Column 80: Couldn't find end of Start Tag td line 1 Line 1, Col...

What is the best practice for writing sql queries inside c# code

On my current project I'm using SQL CE. Since it doesn't have support for stored procedures I have to write sql queries inside repository. Option 1: StringBuilder query = new StringBuilder(); query.Append("SELECT"); query.Append(" c.CUSTOMER_ID,"); query.Append(" COALESCE (c.FIRST_NAME, '') + ' ' + COALESCE (c.LAST_NAME, '') AS F...

reduce, or explicit recursion?

I recently started reading through Paul Graham's On Lisp with a friend, and we realized that we have very different opinions of reduce: I think it expresses a certain kind of recursive form very clearly and concisely; he prefers to write out the recursion very explicitly. I suspect we're each right in some context and wrong in another, ...

Does gcc emit different output in one-liners with/without braces

I tried to use astyle to format the code base I've to work with. When I use the option --add-brackets the executable is not identical (If I only use -t and/or -b the output is identical). if(a) return b is modified to if(a) { return b } So my question is. Does gcc generate the same output if I only add and/or delete braces (ob...

Is it wrong to use braces for variable scope purposes?

Hi, I sometimes use braces to isolate a block of code to avoid using by mistake a variable later. For example, when I put several SqlCommands in the same method, I frequently copy-paste blocks of code, ending by mixing the names and executing twice some commands. Adding braces helps to avoid this situation, because using a wrong SqlComm...

Function and declaring a local variable

Just having an conversation with collegue at work how to declare a variables. For me I already decided which style I prefer, but maybe I wrong. "C" style - all variable at the begining of function. If you want to know data type of variable, just look at the begining of function. bool Foo() { PARAM* pParam = NULL; bool rc; ...

Is there a more Pythonic way of changing `None` to `[]` than...

Is there a more Pythonic way of doing this?: if self.name2info[name]['prereqs'] is None: self.name2info[name]['prereqs'] = [] if self.name2info[name]['optionals'] is None: self.name2info[name]['optionals'] = [] The reason I do this is because I need to iterate over those later. T...

why have the modified if position in scala?

So I'm learning Scala and came across some examples like this: val doubleEven = for (i <- 1 to 10; if i % 2 == 0) yield i * 2 Now, what's the added benefit to having this special syntax built into the for loop as opposed to the time-honored val doubleEven = for(i <- 1 to 10){ if(i % 2 == 0) yield i*2 } style if? EDIT: Of ...

Why are good Coders bad Designers?

Why are good Developers bad Designers? and why are good Designers bad Developers. How can this lack fixed of both sides? Should coders beginn to draw? to fix this lack? and should Designers beginn to study Math to fix this lack? ...