coding-style

Was it a big mistake of JavaScript language inventor to use function instead of a shorter word ?

It seems that it would be wise to use def, fn, or fun for function definitions similar to Ruby or other succinct languages. Now that it's too late to change things due to potential compatibility issues, the whole world is forced to suffer using that wasteful long name 'function' everywhere in JavaScript code. ...

more pythonic way of finding element in list that maximizes a function

OK, I have this simple function that finds the element of the list that maximizes the value of another positive function. def get_max(f, s): # f is a function and s is an iterable best = None best_value = -1 for element in s: this_value = f(element) if this_value > best_value: best = element...

Using true and false in C

As far as I can see there are 3 ways to use booleans in c with the bool type, from then using true and false defining using preprocessor #define FALSE 0 ... #define TRUE !(FALSE) Just to use constants directly, i.e. 1 and 0 are there other methods I missed? What are the pros and cons of the different methods? I suppose the fastest...

Naming guidelines - Naming generic objects

MSDN Guidelines states that class names should be Pascal cast with no special prefix, such as "C". It is also states that names of class members, such as proprties and fields, should also be Pascal cast. So, names ambiguity may arise in the case of a naming generic object. for example, consider a class named "Polynom". An object instanti...

Clean way to refactor test code

Background: I currently write test cases for the client side of a network protocol. As part of the tests I have to simulate several different expected and unexpected responses from the server (wrong header, connection lost, unexpected messages, timeouts). Each of these test-cases can be accessed by its unique address. My problem: The cur...

Code readability vs conciseness

What are the merits and demerits of the following two code snippets: return n==0 ? 0 : n==1 ? 1 : fib(n-1) + fib(n-2); and if(n==0) return 0; if(n==1) return 1; return fib(n-1) + fib(n-2); for calculating the nth letter in the Fibonacci sequence? Which one would you favour and why? ...

How to deal with with programmers who refuse to indent their code?

The firm where I work has programmers who still don't seem to understand the importance of indentation and write all the code aligned to left margin. What arguments can I put to convince them of the importance of indentation? ...

next verus if in a .each loop?

Hello, I have a text processing thing I'm doing in Ruby. Basically, I have to implement a simple state machine(with one character look-behind My code at the moment looks like this: text.each{ |c| ... ... ... ... if @state!=:some_state next end #processing stuff for if in :some_state mode ... ... ... ... ... ...

Event handler raising method convention

I was just browsing and came across this question: Action vs delegate event The answer from nobug included this code: protected virtual void OnLeave(EmployeeEventArgs e) { var handler = Leave; if (handler != null) handler(this, e); } Resharper also generates similar code when using the "create raising method" quick-fix. My ...

Where do non-traditional programmers (especially engineers/scientists) go wrong?

Soon, I expect to be asked to revise and improve existing code written by engineers and scientists. I've noticed that non-programmers do not share the same programming 'eye' as computer-scientists and full-time programmers. As someone coming from a non-computer-science background, I want to know what mistakes non-traditional programmer...

ObjC: How bad is to directly assign to a property and the release it?

I'm wondering how bad is the following code for experienced objective-C programmers. self.request = [[ASIHTTPRequest alloc] initWithURL:url]; [self.request release]; It is definitely less verbose this ASIHTTPRequest *tmp = [[[ASIHTTPRequest alloc] initWithURL:url]; self.request = tmp; [tmp release]; But I'm not sure if it is meanin...

How does one know when to newline in Clojure/Lisp in general?

Here is a bit of example code: (deftype Deck52 [suits] :as this DeckOfCards (check-empty [] (Deck52. (apply hash-map (apply concat (remove (-> nil?) (for [[key val] suits] (if (emp...

Why is it recommended to have empty line in the end of file?

Some code style tools recommend this and I remember seeing some unix command line tools warning about missing empty line. What is the reasoning for having an extra empty line? ...

What are best practices for including parameters such as an accumulator in functions?

I've been writing more Lisp code recently. In particular, recursive functions that take some data, and build a resulting data structure. Sometimes it seems I need to pass two or three pieces of information to the next invocation of the function, in addition to the user supplied data. Lets call these accumulators. What is the best way to...

From where to start coding a software?

The project which I am going to start is my first project and it is very big. Though it's a great opportunity for me, I don't want me to trapped myself in a messed-code in the end so I have made a whole design of the software (software architecture) divided it into three tiers: Presentation Tier ---- (will be implemented through Java S...

putting a capital 'I' in front of JAVA interfaces

Many years ago when I was at uni they said to put a capital i (I) in front of interfaces. Is this still a convention because I see many interfaces that do not follow this. ...

Is this sort of Java exception style bad practice?

Is it considered bad practice to structure the code like this? public void whatever() { try { methodThatMayThrowIOException(); } catch(IOException io) { // do something with exception here } // do more stuff here that won't throw exceptions try { methodThatMayThrowCustomException(); } catch(CustomExcep...

Legible or not: C# multiple ternary operators + Throw if unmatched.

Do you find the following C# code legible? private bool CanExecuteAdd(string parameter) { return this.Script == null ? false : parameter == "Step" ? true : parameter == "Element" ? this.ElementSelectedInLibrary != null && this.SelectedStep != null : parameter == "Choice" ? this.SelectedElement != null...

Where should sys.path.append('...') statement go?

Just after standard pythonmodule imports? If I postpone it to the main function and do my specific module imports before it, it gives error (which is quite obvious). Python Style guide no where mentions the correct location for it. ...

Managing line width in ColdFusion

If you work with ColdFusion, you've probably gotten used to either line-wrapping or horizontal scrolling. Infrequently, this isn't so bad, but when three out of four lines in an existing code base are wrapped, sometimes twice, it becomes a huge readability hindrance. A line such as... <cffunction name="v_multiple_item" access="public"...