Which of these 2 programming styles do you prefer? Why? Are there particular advantages to one over the other?
// Style 1
if (doBorder)
doTheBorder();
if (doFrame)
doTheFrame();
if (doDraw)
doTheDraw();
void doTheBorder()
{
// ...
}
void doTheFrame()
{
// ...
}
void doTheDraw()
{
// ...
}
// Style 2
doTheBorder();
...
When I see website starter code and examples, the CSS is always in a separate file, named something like "main.css", "default.css", or "Site.css". However, when I'm coding up a page, I'm often tempted to throw the CSS in-line with a DOM element, such as by setting "float: right" on an image. I get the feeling that this is "bad coding", s...
I know this is a fairly contentious issue amongst programmers, but when developing I like my IDE to position the opening curly bracket underneath the method/interface/control declaration, for illustrative purposes: -
This is how Xcode automatically generates skeleton methods with the { at the end: -
-(void) isTrue:(BOOL)input {
if(...
Hi,
I have a python class which reads a config file using ConfigParser:
Config file:
[geography]
Xmin=6.6
Xmax=18.6
Ymin=36.6
YMax=47.1
Python code:
class Slicer:
def __init__(self, config_file_name):
config = ConfigParser.ConfigParser()
config.read(config_file_name)
# Rad the lines from the file
...
I want that whatever code style i defined in eclipse editor ..should be followed by coders, so can i enforce it as program will not even build without satisfying all the rules???
...
I believe, I program good, at least my code produces results...
But I feel I have drawback... I hardly follow any naming conventions... neither for variables.. nor for methods... nor for classes... nor for tables, columns, SPs... Further to this, I hardly comment anything while programming...
I always think that, Let me first see t...
Lets say you have:
if(condition) {
i = 1;
} else {
i = 2;
}
and you need to put comments explaining if and else blocks. What's the most readable way of doing it so someone can easily pick them up at first glance?
I usually do it like this:
//check for condition
if(condition) {
i = 1;
} else {
//condition isn't met
...
It often happens to me to handle data that can be either an array or a null variable and to feed some foreach with these data.
$values = get_values();
foreach ($values as $value){
...
}
When you feed a foreach with data that are not an array, you get a warning:
Warning: Invalid argument supplied for foreach() in [...]
Assuming i...
Hi.
Is there a way to run the changed files through a filter before doing the commit? I wish to make sure the files follows the coding standards for the project.
I would also like to compile and run some test before the commit/push actually takes place, so I know everything in the repo actually works.
...
Is there any ActionScript 3 Style Guide available online?
...
Hey all,
I use MySQLdb a lot when dealing with my webserver. I often find myself repeating the lines:
row = cursor.fetchone()
while row:
do_processing(row)
row = cursor.fetchone()
Somehow this strikes me as somewhat un-pythonic. Is there a better, one-line way to accomplish the same thing, along the lines of inline assignme...
When I'm writing it?
After I got a part done (Single class/function/if-elses)?
After I got the whole thing working?
...
Is it bad to write:
if (b == false) //...
while (b != true) //...
Is it always better to instead write:
if (!b) //...
while (!b) //...
Presumably there is no difference in performance (or is there?), but how do you weigh the explicitness, the conciseness, the clarity, the readability, etc between the two?
Update
To limit the su...
Hey all!
So, I was just coding a bit today, and I realized that I don't have much consistency when it comes to a coding style when programming functions. One of my main concerns is whether or not its proper to code it so that you check that the input of the user is valid OUTSIDE of the function, or just throw the values passed by the us...
When I code, I always write little pieces of unit, and compile it often. This helps me to make sure that everything run correctly, but it's very time consumed. is there any programming language that can support us to do coding and running at the same time side by side ? i mean as soon as a key press leads to valid code, the effect of the...
Hi
I have the following code sample, where the only difference between the 2 parts of the If statement is the less than/greater than operators.
Is there a better way to write this? Could almost do with being able to define an Operator variable.
If myVar = true Then
Do While (X < Y)
'call Method A
...
I was wondering what was the most clean and understandable syntax for doing condition checks on nullable bools.
Is the following good or bad coding style? Is there a way to express the condition better/more cleanly?
bool? nullableBool = true;
if (nullableBool ?? false) { ... }
else { ... }
especially the if (nullableBool ?? false) p...
I've been working on a foundational c++ library for some time now, and there are a variety of ideas I've had that could really simplify the code writing and managing process. One of these is the concept of introducing some macros to help simplify statements that appear very often, but are a bit more complicated than should be necessary. ...
Given the following code snippets, is there any appreciable difference?
public boolean foo(int input) {
if(input > 10) {
doStuff();
return true;
}
if(input == 0) {
doOtherStuff();
return true;
}
return false;
}
vs.
public boolean foo(int input) {
if(input > 10) {
doStuff();
...
How many max number of lines of code one .cs file should hold. Are there any industry standards/best practices?
...