Are All Programming Languages The Same?

Every LOC counting method I’ve seen for C and C-style languages does not count lines that only contain a brace.

For example, a coder could write an if block two possible ways:

if(condition)
{
    DoSomething();
    DoSomethingElse();
}

or…

if(condition) {
    DoSomething();
    DoSomethingElse();
}

The first one yields 5 lines, and the second yields 4. If LOC is ever used to measure productivity or efficiency, breaking to the next line should not be awarded/penalized for the programmer’s coding style. As VB does not use the brace in this fashion, the only lines that shouldn’t be considered are whitespace.

On another note, I think people that put the opening brace on a conditional/loop/other construct are evil. :stuck_out_tongue:

Last line should have read:

On another note, I think people that put the opening brace on the same line as a conditional/loop/other construct are evil. :stuck_out_tongue:

Think about it a good moment.

A closing bracket IS a line of code, because it DOES do something. (At least in C++). What happens on the closing bracket in C++, might you ask? Deconstructors for all objects that were declared in that set of brackets are executed when the ending bracket is reached. That can be a lot of processing done at that ending bracket that wouldn’t be counted otherwise!

“I agree with Brandon that a line with a bracket is a LineOfCode, except for python ;-)”

There’s no reason a line containing only a bracket should be counted as a line of code. As an example, say you’re using LOC counts as efficiency, so a lower LOC reflects a more efficient programmer. If you’re counting “brace lines”, then a programmer may change his style to show a greater efficiency.

Example:
if(condition)
{
DoSomething();
DoSomethingElse();
}

Counting brace lines, that snippet contains five LOC. Assuming indentation(which I don’t know how to force in these comments :P), this code is very readable.

Now, we can reduce that snippet to three LOC, just by keeping braces on the same line, like so:

if(condition){
DoSomething();
DoSomethingElse(); }

You lose readability by doing this(IMO), but reduce your total LOC. However, the main point is that they do the same thing, despite where you place the braces. Since they do the same exact thing, why should a programmer be punished(or rewarded in some cases) for making more readable code.

Of course, all of this can be resolved by implementing and enforcing coding standards at your company, but this is about as rare as code reviews.

PHP should be added to the list.

<?php
$filename = "readAFile.php"
@readfile ($filename);
?>

Or with “checks”

<?php
$filename = "readAFile.php"
if (file_exists ($filename) && is_readable($filename))
     readfile ($filename);
else
    echo "Error reading file, or file not found."
?>

https://php.net/manual/en/function.readfile.php
https://www.php.net/manual/en/function.file-exists.php

Visual Fox in just 2 lines of code:

ON ERROR wait window "Error reading file, or file not found."
?FILETOSTR("filename.txt")