coding-style

Javascript file as an anonymous function

I have been reading a lot of Javascript lately and I have been noticing that the whole file is wrapped like the following in the .js files to be imported. (function() { ... code ... })() What is the reason for doing this rather than a simple set of constructor functions? ...

what code it better

<% if (condition) { %> <%= variable %> <% } %> or <% if (condition) { Response.write(variable); } %> ...

indentation preference and personality

This question is similar in spirit to : http://stackoverflow.com/questions/492178/links-between-personality-types-and-language-technology-preferences But it is based specifically on indentation (spaces vs tabs and the number of spaces). The reason I am asking here instead of searching is because I remember seeing a specific document w...

Java - when to use 'this' keyword

What is the best practise for using the this keyword in Java? For example, I have the following class: class Foo { Bar bar; public Foo(Bar bar) { this.bar = bar; } } That's fine and all, but Java is clever enough to know what is happening if I change the statement in the constructor to bar = bar; So why use t...

Links to official style guides

C++ has several types of styles: MFC, Boost, Google, etc. I would like to examine these styles and determine which one is best for my projects, but I want to read from the official style guidebook. Does anyone have an official guide that they typically use? Here are two that I found. I bet there are more: http://google-styleguide.g...

Semantic #region usage

What's your opinion about using #region folding using application semantic, instead of folding for "syntax". For example: #region Application Loop #region User Management #region This Kinf of stuffs instead of #region Private Routines #region Public Properties #region ThisRoutine // (Yes, I've seen this also!) In this logic, I'm s...

Elegant check for null and exit in C#

What is an elegant way of writing this? if (lastSelection != null) { lastSelection.changeColor(); } else { MessageBox.Show("No Selection Made"); return; } changeColor() is a void function and the function that is running the above code is a void function as well. ...

How to override virtual function in good style? [C++]

Hi, guys I know this question is very basic but I've met in few publications (websites, books) different style of override virtual function. What I mean is: if I have base class: class Base { public: virtual void f() = 0; }; in some publications I saw that to override this some authors would just say: void f(); and some would ...

Advice on my jQuery Ajax Function

So on my site, a user can post a comment on 2 things: a user's profile and an app. The code works fine in PHP but we decided to add Ajax to make it more stylish. The comment just fades into the page and works fine. I decided I wanted to make a function so that I wouldn't have to manage 2 (or more) blocks of codes in different files. Rig...

XML: When to use attributes instead of child nodes?

Possible Duplicates: XML Attributes vs Elements Should I use Elements or Attributes in XML? For tree leaves in XML, when is it better to use attributes, and when is it better to use descendant nodes? For example, in the following XML document: <?xml version="1.0" encoding="utf-8" ?> <savedGame> <links> <link rootTag...

Function return type style

I'm learning c++0x, at least the parts supported by the Visual C++ Express 2010 Beta. This is a question about style rather than how it works. Perhaps it's too early for style and good practice to have evolved yet for a standard that isn't even released yet... In c++0x you can define the return type of a method using -> type at the end ...

What's the catch to create _names _of _fields _like _these in java?

From time to time I see something like this: class Clazz { private int _goodName; private int _anotherGoodName; ... } I don't get it. It's hard and unusual to read such code. What are the pros? ...

When should I use Perl's AUTOLOAD?

In "Perl Best Practices" the very first line in the section on AUTOLOAD is: Don't use AUTOLOAD However all the cases he describes are dealing with OO or Modules. I have a stand alone script in which some command line switches control which versions of particular functions get defined. Now I know I could just take the conditionals...

StyleCop XML Documentation Header - Using 3 /// instead of 2 //

I am using XML documentation headers on my c# files to pass the StyleCop rule SA1633. Currently, I have to use the 2 slash commenting rule to allow StyleCop to recognize the header. for example: // <copyright file="abc.ascx.cs" company="MyCompany.com"> // MyCompany.com. All rights reserved. // </copyright> // <author>Me</author> ...

Why is there so much poorly indented code out there?

The more I browse the code to open source projects in languages that aren't Python, the more I realize that it seems a lot of programmers don't believe in proper indentation. (I won't mention any projects specifically to avoid having anyone take this question too personally.) Usually code is indented, but in a way just different enough...

Get a list of every value for a given key in a set of dictionaries?

How can I write this code more cleanly/concisely? /// <summary> /// Creates a set of valid URIs. /// </summary> /// <param name="levelVariantURIDicts">A collection of dictionaries of the form: /// dict["filePath"] == theFilePath </param> /// <returns></returns> private ICol...

What human learning techniques can be applied to improve code layout?

Is it possible to use the results of studies made into human learning in order to identify how code might be laid out to improve comprehension? Code layout wars almost always end up defending consistency and the prevailing style, but could there be ways of laying out code that are provably better than others? ...

C# new class with only single property : derive from base or encapsulate into new ?

I've tried to be descriptive :) It's rather programming-style problem than coding problem in itself. Let's suppose we have : A: public class MyDict { public Dictionary<int,string> dict; // do custom-serialization of "dict" public void SaveToFile(...); // customized deserialization of "dict" public void LoadFr...

Did anyone create the Java Code Formatter Profile for Eclipse IDE that conforms to the Android Code Style Rules?

Android Code Style Guide defines "Android Code Style Rules". To conform to these rules one have to change quite a number of settings of the Java Code Formatter (Window->Preferences->Java->Code Style->Formatter) default profile (in Eclipse IDE). Did anyone manage to configure the formatter to follow the "Android Code Style Rules" already...

Following PHP coding of Wisdom

i read some wisdom like this : Programmers are encouraged to be careful when using by-reference variables since they can negatively affect the readability and maintainability of the code. i make my own solution, such as give suffix such as _ref in every by-reference variables. so, if i have a variable named as $files_in_root, then i ...