coding-style

Best standards for declaring variable in php

can any one please let me know the global declaration of php variables..i have seen one among the site like.. for integer start with i, eg: $iItemId for array start with a, eg: $aItemIds for string start with s, eg: $sItemName ...

A regular expression that moves opening { braces to a new line, for C/C++/PHP/etc code

This kind of code structure makes, IMHO, code less readable: int func() { [...] } It's just a matter of taste, but I prefer this one: int func() { [...] } So I've trying to make a regular expression to apply in my text editor in order to make code in the first example look like the second one. I've come up with something lik...

Origin of discouraged perl idioms: &x(...) and sub x($$) { ... }

In my perl code I've previously used the following two styles of writing which I've later found are being discouraged in modern perl: # Style #1: Using & before calling a user-defined subroutine &name_of_subroutine($something, $something_else); # Style #2: Using ($$) to show the number of arguments in a user-defined sub sub name_of_sub...

In Python, is it better to use list comprehensions or for-each loops?

Which of the following is better to use and why? Method 1: for k, v in os.environ.items(): print "%s=%s" % (k, v) Method 2: print "\n".join(["%s=%s" % (k, v) for k,v in os.environ.items()]) I tend to lead towards the first as more understandable, but that might just be because I'm new to Python and list comprehensions a...

Is there a concise way to map a string to an enum in Objective-C?

I have a string I want to parse and return an equivalent enum. I need to use the enum type elsewhere, and I think I like how I'm defining it. The problem is that I don't know a good way to check the string against the enum values without being redundant about the order of the enums. Is there no option other than a big if/else? typedef ...

How do you PEP 8-name a class whose name is an acronym?

I try to adhere to the style guide for Python code (also known as PEP 8). Accordingly, the preferred way to name a class is using CamelCase: Almost without exception, class names use the CapWords convention. Classes for internal use have a leading underscore in addition. How can I be consistent with PEP 8 if my class name is form...

How to avoid "incomplete implementation" warning in partial base class

I have created a protocol that my classes need to implement, and then factored out some common functionality into a base class, so I did this: @protocol MyProtocol - (void) foo; - (void) bar; @end @interface Base <MyProtocol> @end @interface Derived_1 : Base @end @interface Derived_2 : Base @end @implementation Base - (void) foo{ //...

NAMESPACE_SEPARATOR constant

Hello, Having namespaces in PHP is great. Having '\' as namespace separator is a little bit ... awkward (but if there is someone who thinks that is cool & sexy, I am adding tag "rant" to this post. ;) . So, here goes the question: Are you using in your code NAMESPACE_SEPARATOR constant? As in code below: <?php if (!\defined('NAME...

How should I name form controls variables and their event handlers in WinForms?

Hello, I have a little coding style problem - what names should I choose for controls in Windows Forms in my application? I think that best approach is to not generate the field at all (GenerateMember property), this can work at buttons, separators, menu items etc. But there are for example some labels and controls that I need to refere...

including .h files.

Suppose I have two .h files: A.h and B.h. Moreover, A.h includes B.h itself: B.h - defines class B. class B { ... }; A.h - defines class A, which uses class B. #include B.h class A { void SomeFunction(const B& b); }; Now, I have some .cpp file, that uses both A and B classes (B class maybe used not only in A::SomeFunction(B))...

Java Code Formating

I'm using FreeMarker to generate java code, but as most of it is dynamically generated it's difficult to control the code formation. I want to get code well formatted. Does anyone knows a lib or something like a pretty printer for java code? ...

A question of style/readability regarding the C# "using" statement

I'd like to know your opinion on a matter of coding style that I'm on the fence about. I realize there probably isn't a definitive answer, but I'd like to see if there is a strong preference in one direction or the other. I'm going through a solution adding using statements in quite a few places. Often I will come across something like ...

How to use SQLiteOpenHelper without or less restrictive use of Context?

If you extend SQLiteOpenHelper, for the Constructor you have to use a Context. I am wondering if there is a way to leave this out, and be able to work with database tables without a Context. Or at least be least restrictive, I mean a way of project/class structure that will make history the several context passings I have to do now. A...

Python: When passing variables between methods, is it necessary to assign it a new name?

I'm thinking that the answer is probably 'no' if the program is small and there are a lot of methods, but what about in a larger program? If I am going to be using one variable in multiple methods throughout the program, is it smarter to: Come up with a different phrasing for each method (to eliminate naming conflicts). Use the same nam...

Is there a recommended maximum line length for HTML or JavaScript?

Most style guidelines for most programming languages recommend a maximum line length, typically 80 characters. This seems impractically short for HTML and JavaScript (when it is embedded in HTML). Is there a consensus on a practical line length limit for HTML/JavaScript? Or is it generally left up to the developer's common sense? ...

What are the advantages of squashing assignment and error checking in one line?

This question is inspired by this question, which features the following code snippet. int s; if((s = foo()) == ERROR) print_error(); I find this style hard to read and prone to error (as the original question demonstrates -- it was prompted by missing parentheses around the assignment). I would instead write the following, which ...

Implicit vs explicit getters/setters in AS3, which to use and why?

Since the advent of AS3 I have been working like this: private var loggy:String; public function getLoggy ():String { return loggy; } public function setLoggy ( loggy:String ):void { // checking to make sure loggy's new value is kosher etc... this.loggy = loggy; } and have avoided working like this: private var _loggy:String;...

difference between form id and form name used in html.

i want to know the exact difference between form id and form name used in html. ...

Style of if: to nest or not to nest

A colleague of mine and me had a discussion about the following best-practice issue. Most functions/methods start with some parameter checking. I advocate the following style, which avoids nesting. if (parameter one is ugly) return ERROR; if (parameter two is nonsense || it is raining) return ERROR; // do the useful stuff return result...

codingstyle "blanking after open and before close brackets"

Hi, I really like the "blanking after open and before close brackets"-codingstyle in modern codes Java/C#/C++ . e.g. calling a function: foo(myparam); // versus foo( myparam ); Do you have a better name for this codingstyle? where does it come from? Do you like it either, what is the reason for you to use it or not use it? a few years...