Hi,
I'm doing some Perl and seeing my nested "if" statements is driving me mad. I managed to reduce some of them with guard blocks in another section, but I'm stuck here.
Do you think I may leave the code as is, or is there a "proper" way to refactor the following ? (I also admit being relatively new to Perl)
This is actually a subro...
here at office we have a library named after the company name and inside of it sublibraries, per project more or less, and in each sublibrary there might be more modules or libraries. we are using Django and this makes our hierarchy a couple of steps deeper...
I am a bit perplex about the differences among the following import instruct...
I wonder how people are using C++0x lambdas, in terms of coding style. The most interesting question is how thorough to be when writing the capture list. On one hand, the language allows to list captured variables explicitly, and by the "explicit is better than implicit rule", it would therefore make sense to do an exhaustive listing to ...
I've often found that when a programmer or the one assigning the task doesn't really understand how a solution could work, they kind of randomly add stuff until it works.
Examples:
Repainting a window which for some reason isn't painted as the programmer would like it:
Invalidate();
Revalidate();
ProcessMessages();
Update();
Repa...
Maybe this is slightly academic, but if I implement a cache for speeding up an application, how should I best handle cache misses? (In my case, the language would be Java, but maybe the answer can be more general.)
Throw an exception:
ResultType res;
try {
res = Cache.resLookup(someKey);
} catch (NotFoundException e) {
res = Ca...
I'm having a hard time building a Cairngorm Flex3 app that connects to a rails app...
I'm used to rails DRY approad, and the Convention over Configuration thing too.. and Cairngorm in awful at these.
How do you keep you flex code as DRY as possible?
I've implemented a generic delegate to avoid a delegate for each command, at least.
Any...
I have been wracking my brain trying to figure this out. For the first time I used jEdit the other day and I was pleasantly surprised that it auto indented my code (meaning that I'd put in the following code:
int method () {
_ //<-- and it put me here automatically
I've tried to get the same thing working with eclipse but with no ...
Do you have such a habit that when you
are coding, you write the
documentation as well, and make sure
that they are in sync.
How can achieve
that? What do you write down? The
function logical? The concept? Or
other best-practices? Thanks in
advance!
...
Which way is better practice: return a value from a method inside an using statement or declare a variable before, set it inside and return it after?
public int Foo()
{
using(..)
{
return bar;
}
}
or
public int Foo()
{
var b = null;
using(..)
{
b = bar;
}
return b;
}
...
I need a good variable name for a boolean value that returns false when an object is the last in a list.
The only decent name I can come up with is 'inFront', but I don't think that is descriptive enough.
Another choose would be 'isNotLast'. This is not good practice though (Code Complete, page 269, Use positive boolean variable nam...
A lot of C++ code uses syntactical conventions for marking up member variables. Common examples include
m_*memberName* for public members (where public members are used at all)
_*memberName* for private members or all members
Others try to enforce using this->member whenever a member variable is used.
In my experience, most larger c...
I know it doesn't matter to the compiler, but for best programming practices are any of these a superior style to the other?
function myfunction () {
}
or
function myfunction ()
{
}
I have seen both and sometimes I see:
function myfunction ()
{
if (something) {
}
}
so it is mixed.
I remember seeing some people say that ...
I always wondered: Are there any hard facts which would indicate that either shorter or longer identifiers are better?
Example:
clrscr()
opposed to
ClearScreen()
Short identifiers should be faster to read because there are fewer characters but longer identifiers often better resemble natural language and therefore also should be f...
Inspired by this question which started out innocently but is turning into a major flame war.
Let's say you need to a utility method - reasonably straightforward but not a one-liner. Quoted question was how to repeat a string X times. How do you decide whether to use a 3rd party implementation or write your own?
The obvious downside to...
Consider the following contrived example:
void HandleThat() { ... }
void HandleThis()
{
if (That) return HandleThat();
...
}
This code works just fine, and I'm fairly sure it's spec-valid, but I (perhaps on my own) consider this unusual style, since the call appears to return the result of the function, despite the fact that ...
I remember reading in Douglas Crockford's "Javascript the Good Parts" book that there is potential for error with blockless statements because of automatic semicolon insertion.
if (condition)
foo = true;
vs
if (condition)
{
foo = true;
}
In the second the example it will work consistently, in the first example a semicolon wi...
In Objective-C 2.0 we got the "dot" notation for properties. I've seen various back and forths about the merits of dot notation vs. message notation. To keep the responses untainted I'm not going to respond either way in the question.
What is your thought about dot notation vs. message notation for property accessing?
Please try to...
After you've been programming for a long time with a language, you pick up certain coding standards or styles. With Delphi it's things like prefixing private variables with f and putting private declarations before protected, which in turn are before public ones etc etc. Most of this comes from the VCL.
Is there any recognized coding st...
One of the things that can be a little annoying about Java is the amount of code you need to express concepts. I am a believer in the "less code is better" philosophy, and I'd like to know how I can write Java without being so frustratingly verbose. Recently, I read the Hidden Features of Java question and was introduced to using double-...
This question might seem stupid but i nonetheless i believe it's a worth asking questioin.
I work on some web application when we use tags which are attached to articles.
When adding new article users provides a list of tags he wish to associate with his new article.
So when the form is submitted and my MVC controller processes reques...