Which is the best way of validating an input passed to the function i.e. do you validate all input before proceeding some thing like
class A;
void fun(A* p)
{
if(! p)
{
return;
}
B* pB = p->getB();
if(! pB)
{
return;
}
.......
}
Or do you write it like this:
void fun(A* p)
{
if(p)
{
B* pB = p->getB();
...
35 lines, 55 lines, 100 lines, 300 lines? When you should start to break it apart? I'm asking because I have a function with 60 lines (including comments) and was thinking about breaking it apart.
long_function(){ ... }
into:
small_function_1(){...}
small_function_2(){...}
small_function_3(){...}
The functions are not going to be u...
Should you declare the getters/setters of the class inside the .h file and then define them in .cpp Or do both in .h file. Which style do you prefer and why? I personally like the latter wherein all of them are in .h and only methods which have logic associated with it other than setters/getters in .cpp.
...
I've discovered a new pattern. I wonder if anyone else has this pattern or has any opinion about it.
Basically, I have a hard time scrubbing up and down source files to figure out what module imports are available and so forth, so now, instead of
import foo
from bar.baz import quux
def myFunction():
foo.this.that(quux)
I move a...
Are there any existing tools for applying an arbitrary lint to PHP code? I know about the command line flag (-l) and pecl extension that will check an input file for valid syntax. What I want is a tool that will let me reject something if it has a certain valid but undesirable syntax.
For example, the lint might reject this
if ($foo) ...
What tools do you use for automated code sanity checks and adhering to the coding conventions in your Ruby apps? How do you incorporate them into your process? (I mean tools like roodi, reek, heckle, rcov, dcov, etc.)
...
When inheriting applications at a new job do you tend to stick to the original developers coding practices or do you start applying your own?
I work in a small shop with no guidelines and always wondered what the rule was here. Some applications are written very well but do not follow the standards I use (variable names etc...) and I d...
This is mostly a stylistic question but I've been curious what others' thoughts are since I started programming for the iPhone. When you have a UIView in your iPhone application and you need to access it elsewhere in your application (generally in another function in a view controller), do you like to tag the view with an integer and re...
They both do the same thing. Is one way better? Obviously if I write the code I'll know what I did, but how about someone else reading it?
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
return RedirectToAction("Open", "ServiceCall");
OR
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUr...
I see that Flex3 has a class called ApplicationControlBar dedicated to "holding components that provide global navigation and application commands." (quoted from the langref). The question is: is there an advantage of using this class instead of just adding a plain HBox with a greyish background, or is it just a matter of taste?
In my c...
I have to write an ASP.NET application that connects to our legacy IBM Universe Database and we are using a product called mv.net which allows us to connect, read, write, select, run server side programs, etc.
I want as little code repetition as possible but I also want as little data transfer as possible as well.
In order to open ...
For the following block of code:
For I = 0 To listOfStrings.Count - 1
If myString.Contains(lstOfStrings.Item(I)) Then
Return True
End If
Next
Return False
The output is:
Case 1:
myString: C:\Files\myfile.doc
listOfString: C:\Files\, C:\Files2\
Result: True
Case 2:
m...
I want to create an array/list of strings of the Comma seperated strings (file extensions) that are entered in a Textbox.
For the following block of code:
Dim csv As String = Textbox1.Text + ","
While csv.IndexOf(".") <> -1
lstOfStrings.Add(csv.Substring(0, csv.IndexOf(",")))
csv...
I'm looking for a tool to enforce coding styles, validation check for T-SQL script. And it recommends best-practice when appliable.
In .net code domain, the tool for this purpose is FxCop. Is there a counterpart for T-SQL? It will be best it is free or open source tool.
Anyone can shed some light?
...
Right now resharper formats our code like this:
private readonly List<Folder> folders = new List<Folder>
{
new Folder()
};
but I want it to look like this:
private readonly List<Folder> folders = new List<Folder...
I have seen numerous examples of lazy loading - what's your choice?
Given a model class for example:
public class Person
{
private IList<Child> _children;
public IList<Child> Children
{
get {
if (_children == null)
LoadChildren();
return _children;
}
}
}
The Pers...
Which style is preferred?
Is there a good reason for one vs. the other?
Thanks in advance!
1) cmds.each do |cmd|
end
2) cmds.each { |cmd|
}
Example code:
cmds = [ "create", "update", "list", "help" ]
# Block style one
#
cmds.each do |cmd|
puts "loop1, cmd: #{cmd}"
end
# Block style two
#
cmds.each { |cmd|
puts "loop2, c...
He is good programmer (won some competitions) but he absolutely ignores formatting.
He consider i, j, k beautiful... I hope he won't find out about existence of goto keyword.
...
I can't understand the motivation of PHP authors to add the type hinting. I happily lived before it appeared. Then, as it was added to PHP 5, I started specifying types everywhere. Now I think it's a bad idea, as far as duck typing assures minimal coupling between the classes, and leverages the code modularization and reuse.
It feels li...
Duplicate:
What are Code Smells? What is the “best” way to correct them?
I was just curious about what kind of items cause developers to go "Oh, this code smells off", either language-specific or -agnostic. I know some that personally make me flare my nostrils are
Nested ifs (low readability, probably too complex);
Pointers (do ...