coding-style

Strange #define in Template?

Hello, I've got a small bit of code from a library that does this: #define VMMLIB_ALIGN( var ) var template< size_t M, typename T = float > class vector { ... private: // storage VMMLIB_ALIGN( T array[ M ] ); }; And you can call it by doing //(vector<float> myVector) myVector.array; No parenthesis or anything. what? Afte...

preferred way to organize callbacks

In my Android project, I define a few callbacks to operate on button clicks, connectivity events, or UI events such as Dilaog.onShow(). For demo purposes, I have chosen a Runnable interface that must be launched from some Activity code. With Java, I have different ways to express myself. One pattern would be to use anonymous class runO...

Is there a neater alternative to `except: pass`?

I had a function that returned a random member of several groups in order of preference. It went something like this: def get_random_foo_or_bar(): "I'd rather have a foo than a bar." if there_are_foos(): return get_random_foo() if there_are_bars(): return get_random_bar() raise IndexError, "No foos, no...

How can I make this code Pythonic

So I have this code for an object. That object being a move you can make in a game of rock papers scissor. Now, the object needs to be both an integer (for matching a protocol) and a string for convenience of writing and viewing. class Move: def __init__(self, setMove): self.numToName = {0:"rock", 1:"paper",2:"scissors"} ...

Code line wrapping - how to handle long lines

I'm facing a particular line that is 153 characters long. Now, I tend to break things after 120 characters (of course, this is heavily dependent on where I am and the local conventions.) But to be honest, everywhere I break the line just makes it look bad. So I'm looking for some ideas on what I should do for it. Here's the line: priva...

Sorting methods in class file by access modifiers.

Sorting methods in class file by access modifiers is good or wrong habit? Which are another methods for structure of class file? ...

PHP coding standards at work: Insane, or am I?

I prefer coding standards to be logical. This is my argument for why the following set of standards are not. I need to know one of two things: (1) why I'm wrong, or (2) how to convince my team to change them. camelCase: Functions, class names, methods, and variables must be camelCase. Makes it hard to differentiate between variable...

Website is not compatible in a AOL Browser

I built a website and it looks fine in browsers like IE and Firefox, but the background does not show up in an AOL browser. Is there a special way I need to code the background image or any tips on how to make it compatible? ...

Why should I use <ARGV> or <> instead of <STDIN> in Perl?

Quoting from Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin Perl has a useful magic filehandle called *ARGV that checks the command line and if there are any arguments, opens and reads those as files. If there are no arguments, *ARGV behaves like *STDIN instead. This behavior is almost always what you want if you want to cr...

How to comment/uncomment in HTML code

Hello all Often while coding view templates in html, my habit of adding some helpful comments causes lots of time-consuming effort while testing. Consider this code... <!-- Here starts the sidebar --> <div id="sidebar"> .... </div> <!-- Here starts the main contents pane --> <div id="main-contents"> ... </div> <!-- Here starts the f...

About making new Activities

Hello! I have an Activity with a listView with few options and a button at the bottom of the screen. The listView is just to configurate some options so, when i click in any of the items in the list its needed to let the user choose between some options (in some cases i'll use another list to show the options, in other cases i'll let th...

Better Term than "Decisecond"

I have a data element with units of tenths of a second (that is, the value "123" really means "12.3 seconds"). What is a good term for an descriptive identifier for this type of data? I'd be comfortable writing something like durationMilliseconds or durationMicroseconds, but durationDeciseconds looks odd. durationInTenthsOfSeconds does...

Coding style tool for Delphi 2010

Possible Duplicate: FxCop / StyleCop for Delphi? Hi ! Has anyone encountered with some coding style tool like StyleCop, but for Delphi 2010 ? I would appreciate if someone recommends any free tool. ...

Get rid of ugly if statements

I have this ugly code: if ( v > 10 ) size = 6; if ( v > 22 ) size = 5; if ( v > 51 ) size = 4; if ( v > 68 ) size = 3; if ( v > 117 ) size = 2; if ( v > 145 ) size = 1; return size; How can I get rid of the multiple if statements? ...

Formatting block comments

The first style of formatting seems to be much more popular than the second. Why is that? The first (asterisk on every line) /* * line 1 * line 2 * line 3 */ The second (the minimum amount of asterisks) /* line 1 line 2 line 3 */ ...

Should it be if() or if ()?

When you have line of code with a parenthetical statement, do you include a space before the parenthetical? For example, should it be if() or if () Thanks in advance! ...

How does this control architecture script look?

I am looking for feedback on my control architecture script (included below). Specifically, I am looking for feedback regarding the script's design, organization, commenting, and formatting. I enjoy php programming as a hobby, and am looking to learn where I can improve my code. Thanks in advance! class FrontController extends Acti...

Risky to choose a non-standard Java code indentation style?

Does it make a difference if you choose a non-standard indent style? This is the style I see most often: import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Test { static public void main(String args[]) throws Exception { FileInputStream ...

[C++] Access members directly or always use getters

Note: C++ specific question I personally find it weird/ugly when a class uses a getter to access its own member data. I know the performance impact is none but I just don't like to see all those method calls. Are there any strong arguments either way, or is it just one of those things that's personal preference and should be left to eac...

Why do people always use reassignment for instance variables in objective-C (namely iphone)?

I always see example code where in the viewDidLoad method, instead of saying, for example someInstanceVar = [[Classname alloc] init]; they always go Classname *tempVar = [[Classname alloc] init]; someInstanceVar = tempVar; [tempVar release]; Why is this? Isn't it the exact same thing, just longer? ...