I've tried checking other answers, but I'm still confused--especially after seeing W3schools HTML 5 reference.
I thought HTML 4.01 was supposed to "allow" single-tags to just be <img> and <br>. Then XHTML came along with <img /> and <br /> (where someone said that the space is there for older browsers).
Now I'm wondering how I'm suppos...
I maintain the build for a large J2EE/Maven/Hudson/Perforce project with about 20 developers spread across the world.
The solution in-place for code formatting is to format the codebase using jalopy when the developer runs the build, thereby ensuring any code which has not been formatted gets formatted prior to check-in.
There main pro...
I try to make my code fool-proof, but I've noticed that it takes a lot of time to type things out and it takes more time to read the code.
Instead of:
class TextServer(object):
def __init__(self, text_values):
self.text_values = text_values
# <more code>
# <more methods>
I tend to write this:
class TextServer...
In order to write more concisely, rather than do this:
test_value = method_call_that_might_return_nil()
if test_value
do_something_with test_value
end
I've been assigning in the conditional:
if test_value = method_call_that_might_return_nil()
do_something_with test_value
end
Is this bad style? The still-more-concise syntax:
do...
I'm writing a shell in C. While I don't expect many other people to use it, I'd like to practice writing maintainable and well-organized code. I've noticed the following pattern in a number of my functions, so before it solidifies, I'd like it to be fully vetted.
As an example, consider the following function:
int foo(int param...) {...
A subclass needs to know when particular events occur withing its superclass, but there are more than one ways for the superclass to break the news. Here are 2:
dispatch an event
call an abstract method which the subclass could eventually override
I was wondering if best practices would recommend one of the approaches over the other....
In a response elsewhere, I found the following snippet:
In general it is nicer in C to have
the caller allocate memory, not the
callee - hence why strcpy is a "nicer"
function, in my opinion, than strdup.
I can see how this is a valid pattern, but why might it be considered nicer? Are there advantages to following this patter...
What do you believe in? As an incomplete basis for a good product - would you prefer a mess of code that is horrible to look at but works perfectly for what its supposed to do, or a beautiful set of well organized classes (or something else if OO doesn't float your boat) but have buggy functionality that still needs a lot of work?
If yo...
Could someone provide a link to a good coding standard for Haskell? I've found this and this, but they are far from comprehensive. Not to mention that the HaskellWiki one includes such "gems" as "use classes with care" and "defining symbolic infix identifiers should be left to library writers only."
...
Suppose that you have a lengthy string (> 80 characters) that you want to spread across multiple source lines, but don't want to include any newline characters.
One option is to concatenate substrings:
string longString = "Lorem ipsum dolor sit amet, consectetur adipisicing" +
" elit, sed do eiusmod tempor incididunt ut labore et d...
I saw this today in some PHP code.
$items = $items ?: $this->_handle->result('next', $this->_result, $this);
What is the ?: doing? Is it a Ternary operator without a return true value? A PHP 5.3 thing?
I tried some test code but got syntax errors.
...
I recently started working on a small CMS. I usually develop .NET applications in C#, and I'm very used to commenting my fields and methods. My friend told me earler that having comments in PHP scripts is quite bad, since PHP is dynamic and parsed when requested, so having to parse the comments will take longer.
Does this statement ap...
def a(something):
return something*something
#Case I - referencing
b = a
#Case II - creating a new function to call the first
def b(something):
return a(something)
Which is better style? Are there drawbacks to either?
...
Hi there. At our company's Xmas party we had almost a physical fight over one issue:
whether or not to allow empty lines in a function/method in our code (c/c++/c#). This is all about just single blank line, for example imagine code like:
private void LoadData()
{
if (!loaded)
return;
Dat...
I prefer to use functional OOP style for my code (similar to the module pattern) because it helps me to avoid the "new" keyword and all problems with the scope of "this" keyword in callbacks.
But I've run into a few minor issues with it. I would like to use the following code to create a class.
namespace.myClass = function(){
var sel...
In my C# unit tests, I often query for a list of rows based on a list of IDs. I then want to ensure that 1) for all the IDs, there was at least one row found that has that ID and 2) for all the returned rows, each row has an ID that is in the list of IDs to find. Here is how I usually ensure that:
Assert.IsTrue(ids.All(
id => resu...
I have an object that uses freezes data as such:
sub frozen_data {
my $self = shift;
$Data::Dumper::Indent = 0;
$Data::Dumper::Terse = 1;
return Data::Dumper->Dump( [ $self->{_DATA}, ] );
}
and a corresponding thaw:
sub thaw_data {
my ($self) = @_;
$self->{_DATA} = eval $self->{DATA};
}
this seems to work...
Is there any recommended coding style how to write PowerShell scripts? It's not about how to structure the code (how many functions, if to use module, ...). It's about 'how to write the code so that it is readable'.
In programming languages there are some recommended coding styles (what to indent, how to indent - spaces/tabs, where to ...
I have a class with the fields "deletionDate" and "experiationDate" which could both be undefined, what would mean that the object is whether deleted nor has an expiration date.
My first approach was:
private Date deletionDate = null; // null means not deleted
Having the book "Clean Code" in mind I remember to better use expressive ...
I'd like to invoke the pylint checker, limited to the Error signalling part, as part of my unit testing. so I checked the pylint executable script, got to the pylint.lint.Run helper class and there I got lost in a quite long __init__ function, ending with a call to sys.exit().
anybody ever tried and managed to do so?
the dream-plan wo...