What do you think about using private static methods?
Personally, I prefer using a static private method to non-static as long as it does not require access to any instance fields.
But I heard that this practice violates OOP principles.
Edit: I am wondering from style prospective of view, not performance.
...
I have a large code base and there is lots of repeated, or nearly repeated code all over the place, it's about as unDRY as code can get, but tracking the "duplicates" is hard, so I was wondering if there are any tools for finding potential DRYable code, something like a diff tool or a Hamming distance analizer, don't need language specif...
I would like to ask do You know any programs similar to StyleCop but for C++?
...
Hi,
I'm going to implement a tokenizer in Python and I was wondering if you could offer some style advice?
I've implemented a tokenizer before in C and in Java so I'm fine with the theory, I'd just like to ensure I'm following pythonic styles and best practices.
Listing Token Types:
In Java, for example, I would have a list of fields...
if ($_GET["asdf"]==1) { /* do something */ }
else { /* do something */ }
////////////////////////////
if ($_GET["asdf"]==1)
/* do something */
else
/* do something */
I was told that the first instance was bad by a person I know. I have absolutely no idea whether this is really such bad practice - does it not shorten the amou...
How do you name your GoTo labels? I use rarely often so I'm having a hard time finding good names.
Please refrain from the classical 'goto is evil and eat your code alive discussion'
...
Hello,
In JavaScript, it is possible to declare multiple variables like this:
var variable1 = "Hello World!";
var variable2 = "Testing...";
var variable3 = 42;
...or like this:
var variable1 = "Hello World!",
variable2 = "Testing...",
variable3 = 42;
Is one method better/faster than the other?
Thanks,
Steve
...
Should we declare the variable and initialize it in the same line..
Dim x as string = "dummy"
OR
Dim x as string
x = "dummy"
I have seen some people are fan of declaring everything at the start of the routine and then using them later in the code (for more readability) and others who will initialize variables at the beginning where...
Sometimes you have to write in your source long lines, that are better to break. How do you indent the stuff ceated by this.
You can indent it the same:
very long
statement;
other statement;
That makes it harder to differentiate from the following code, as shown in the example. On the other hand you could indent it one level:
very l...
Hello,
In JavaScript, it seems you can do either write:
new Date().getTime();
...or:
(new Date).getTime();
The first one is logical, but the second one seems a little unusual to me... Is there any difference between these two ways of creating a Date object, and what is the purpose of the second?
Thanks,
Steve
...
Yes, two hated constructs combined. Is it as bad as it sounds or can it be seen as a good way to control usage of goto and also provide a reasonable cleanup strategy?
At work we had a discussion about whether or not to allow goto in our coding standard. In general nobody wanted to allow free usage of goto but some were positive about us...
I thought I would ask this question to see why many examples and people prefer to use inline databinding in the aspx code vs implementing an OnDataBinding event when using WebForms.
For any databound control (eg. Repeater, GridView, etc) I always implement the OnDataBinding method for field level controls if I need to do anything that i...
Ideally you want a schedule that's accommodating and flexible but when it comes to paying the bills and working in a business, that's rarely a luxury programmers have.
I have been fortunate to have the grace of Steve McConnell and Frederick Brooks to tell me what to do if I want to screw up my project and I take their work seriously.
A...
Hello,
This question is a matter of style, since you can always write a for loop or something similar; however, is there a less obtrusive STL or BOOST equivalent to writing:
for (container<type>::iterator iter = cointainer.begin();
iter != cointainer.end();
iter++)
iter->func();
?
Something like (imagined) this:
call_for...
In most JSON serializers/deserializers, the "key" part in a javascript dictionary/hash array is written as a string.
What is the benefit of using a string as the key as opposed to just typing the intended name in?
For example, say I define two objects k1 and k2 like so:
var k1 = { a: 1, b: 2, c: 3 }; // define name normally
v...
Hi there.
I've had quite a long discussion with a friend of mine about the correct and good use of the main method in Java. Basically we have a class like this:
public class AnImporter implements Runnable {
// some methods, attributes, etc.
}
But where to put the main method? I concider it a good practice to "keep code where it belo...
We're going to be integrating StyleCop into our build system in a couple of weeks. Trolling the web gave me some nice ideas for custom rules that could come in handy, such as a rule for filtering for profanity and sorting your members alphabetically (love this one).
Have you written any custom rules? What are they?
...
Edit: There appears to be at least two valid reasons why Smalltalkers do this (readability during message chaining and scoping issues) but perhaps the question can remain open longer to address general usage.
Original: For reasons I've long forgotten, I never use articles in my variable names. For instance:
aPerson, theCar, anObject...
We would like to have an intern go through our source files for spell checking and naming convention enforcement using the Agent Smith plug-in to ReSharper. It would be very nice to minimize the "noise" from ReSharper inspections by disabling all inspection options except those provided by the Agent Smith plug-in. Is this possible?
...
I am using a lot of STL code with std::for_each, bind, and so on, but I noticed that sometimes STL usage is not good idea.
For example if you have a std::vector and want to do one action on each item of the vector, your first idea is to use this:
std::for_each(vec.begin(), vec.end(), Foo())
and it is elegant and ok, for a while. Bu...