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?
...
<% if (condition) { %>
<%= variable %>
<% } %>
or
<% if (condition) {
Response.write(variable);
} %>
...
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...
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...
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...
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...
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.
...
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 ...
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...
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...
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 ...
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?
...
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...
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>
...
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...
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...
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?
...
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...
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...
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 ...