coding-style

Brace placement after init list in C++

For anyone who places braces thus: void f() { stuff(); } How do you prefer to place braces after long initializer lists? The same way? Object::Object() : foo(1) , bar(2) { stuff(); } Or make an exception so you actually see where the init list ends? Object::Object() : foo(1) , bar(2) { stuff(); } Or l...

Automatically Format Document in Visual Studio?

Anyway of invoking the Edit > Advanced > Format Document" VS command automatically when switching away from a document / routinely with a timer / on entering a document? Its really irritating Ctrl+E+D'ing everytime you want to prettify your code. ...

Ruby style question : blocks or inheritance ?

I have some classes that will do something based on some conditions . The conditions are sent as parameters to some methods . My questions is related to ruby coding style : should the conditions be sent as lambdas/blocks , or as some objects that inherit from a condition class ? which is more efficient in terms of OOP ? Thanks ! ...

Is there a standard naming convention for XML elements?

Is there any standard, de facto or otherwise, for XML documents? For example which is the "best" way to write a tag? <MyTag /> <myTag /> <mytag /> <my-tag /> <my_tag /> Likewise if I have an enumerated value for an attribute which is better <myTag attribute="value one"/> <myTag attribute="ValueOne"/> <myTag attribute="value-one"/> ...

How do you embeded your sql queries in php scripts (coding-style)?

Hi, how do you embed your sql scripts in php? Do you just write them in a string or a heredoc or do you outsource them to a sql file? Are there any best practices when to outsource them ? Is there an elegant way to organize this? ...

which is the best practice when creating functions/methods in PHP, do you use arrays or individual variables?

is it considered 'bad practice' to create an fucntion like so: // $arr_member_fields['first_name'] = $_POST['first_name']; // $arr_member_fields['last_name'] = $_POST['first_name']; // $arr_member_fields['email'] = $_POST['email']; // $arr_member_fields['dob'] = $_POST['dob']; // $arr_member_fields['gender'] = $_POST['g...

jQuery Expanding & Collapsing lists

The code expands and collapses a list in which list items can have sublists. Any ideas to refactor this code - especially the toggling part. Is it necessary to use closures here ? $(function() { $('li:has(ul)') .click(function(event){ if (this == event.target) { var that = this; $('li:ha...

Do you refactor in small steps?

Having read Fowler's "Refactoring" for a while, I still often catch myself thinking "I should have done this in smaller steps." -- even when I did not broke my code. Refactoring in small steps is safe, but cost time. It's a trade off between speed and risk -- I try to be strategic in choosing the way how I am refactoring. Nevertheless:...

Notepad++ tabs to spaces

Does anyone know how to convert tabs to spaces in Notepad++? I found a webpage that suggests it's possible (http://www.texteditors.info/notepad-replacements-compared.php) but I couldn't find any information about how to do it. I like to be able to do that because some web forms don't respect code with tabs in it. ...

Code Ordering in Source Files - Forward Declarations vs "Don't Repeat Yourself"?

If you code in C and configure your compiler to insist that all functions are declared before they are used (or if you code in C++), then you can end up with one of (at least) two organizations for your source files. Either: Headers Forward declarations of (static) functions in this file External functions (primary entry points) Stati...

How do I get Visual Studio to generate code using System types (Int32) instead of built-in aliases (int)

Can I get Visual Studio to transform the built-in aliases into the System types? For example, if I define the following interface public interface IExample { Int32 DoWork(String input); } and use VS to automatically generate the interface, I get the built-in types. public class Demo : IExample { public int DoWork(string input...

Am I immoral for using a variable name that differs from its type only by case?

For instance, take this piece of code: var person = new Person(); or for you Pythonistas: person = Person() I'm told constantly how bad this is, but have yet to see an example of the immorality of these two lines of code. To me, person is a Person and trying to give it another name is a waste of time. I suppose in the days before...

Where to perform Parameter Validation within nested methods

Where is the proper place to perform validation given the following scenario/code below: In MethodA only: since this is the public method which is meant to be used by external assemblies? In MethodA and B since both these can be accessed outside the class? Or Methods A, B and C since method C may be used by another internal method (but ...

return statement vs exit() in main()

Should I use exit() or just return statements in main()? Personally I favor the 'return' statements 'cause I feel it's like reading any other function and the flow control when I'm reading the code is smooth (in my opinion). And even if I want to refactor the main() function, having 'return' seems like a better choice than exit(). Does ...

Space Before Closing Slash?

I've frequently seen a space preceding the closing slash in XML and HTML tags. The XHTML line break is probably the canonical example: <br /> instead of: <br/> The space seems superfluous. In fact, I think that it is superfluous. What is the reason for writing this space? I've read that the space solves some "backwards compatibil...

Checkstyle for ActionScript (Flex)

HI, I'm currently working on a project that uses Flex and Java. In Java we easily enforced a coding standard with Checkstyle, and we want to do this for Flex. Does anybody know of a tool similar to Checkstyle that would allow coding standard checks? (I've googled for this but found only one project written in python and it seams abandon...

Initializing disposable resources outside or inside try/finally

I have seen two ways of acquiring and disposing resources. Either: Resource resource = getResource(); try { /* do something with resource */ } finally { resource.close(); } or: Resource resource = null; try { resource = getResource(); /* do something with resource */ } finally { if (resource != null) resource.close(); } I was wonde...

When to exploit type inference in Haskell?

I'm curious as to how often experienced Haskell programmers really use type inference in practice. I often see it praised as an advantage over the always-explicit declarations needed in certain other languages, but for some reason (perhaps just because I'm new) it "feels" right to write a type signature just about all the time... and I'm...

Alphabetizing methods in Visual Studio

Is there any sort of plug-in or tool available for Visual Studio 2008 to alphabetize methods? Ideally I'd like a tool that will alphabetize a selection, or specified type (i.e. only methods, not member variables), either automatically or on-demand. Thanks! ...

When is the right time and the wrong time to do the quick and dirty solution?

When is it the right time and when is it the wrong time to take the quick and dirty approach versus the proper elegant solution? This started from the comments on my question: http://stackoverflow.com/questions/469695/decode-base64-data-in-java. I wanted a way to do something using only internal Java or something I wrote. The only bui...