The Abyss
-
I have single functions longer than that.
Hmm, out of curiosity, any simple bash one-liner or similar script that would check that (C++ code, mostly)? We don't have any automatic code analysis tools running on that code base (yeah, I know...).
-
At least a good portion of it is embedded documentation. Right? Right??
A small portion. In our defense, it's a single class which is basically a wrapper that hides all the gory database access details. In a singleton.
-
Hmm, out of curiosity, any simple bash one-liner or similar script that would check that (C++ code, mostly)?
To check a file,
wc -l
. I measured the functions by looking at the line numbers in my editor, but you might be able to do it more automatically (if you can write relevant REs) using awk, since that's got much more of a subtle state model than your usual bash script has access to.
-
@dkf I think you'd need to count
{}
brace nesting depth and compare the line numbers of top-level braces. Could be done with a shell loop as well, but awk would likely have better performance.
-
I think you'd need to count {} brace nesting depth and compare the line numbers of top-level braces.
In theory, yes (though you'd also need to understand strings and comments to get that right). In practice, you might just be able to look for a
}
in the first column with no further (non-whitespace) characters on the line. Or at least that'd work for me. The more complex part is identifying what the start of a function looks like; it's practical for my code as I tend to write using a very stylised code structure, but I can't answer for anyone else.
-
In practice, you might just be able to look for a
}
in the first column with no further (non-whitespace) characters on the line.Assuming the code file is properly formatted, of course.
-
The more complex part is identifying what the start of a function looks like; it's practical for my code as I tend to write using a very stylised code structure, but I can't answer for anyone else.
In a similar strategy to finding the ending...just look for non-empty unindented lines. If you find another one before you get to a closing brace, assume you had some other sort of declaration that wasn't a function.
-
I think you'd need to count {} brace nesting depth and compare the line numbers of top-level braces.
In theory, yes (though you'd also need to understand strings and comments to get that right). In practice, you might just be able to look for a
}
in the first column with no further (non-whitespace) characters on the line. Or at least that'd work for me. The more complex part is identifying what the start of a function looks like; it's practical for my code as I tend to write using a very stylised code structure, but I can't answer for anyone else.Right; you may want to skip struct/enum definitions. Not sure how you'd want to handle classes.
-
Hmm, out of curiosity, any simple bash one-liner or similar script that would check that (C++ code, mostly)?
To check a file,
wc -l
.Yes, I know, that's what I used to check the size. I was asking about identifying function length, since that requires some parsing of the file itself. This isn't trivial, I think, especially since our code does not put { on the first column (some files use "void f() {") and this is why I'm asking.
There are also stuff like namespace (it's C++), and comments (yes, we have entire commented-out functions... as if the line count by itself wasn't a large enough hint of the code quality...), and { inside strings (yep, we also have a couple of hand-rolled parsers inside that code!), and...
I know that many code analysis tools do that (they are, after all, various degrees of code parsers), but I don't care that much about this tidbit of information that I am ready to spend time fiddling with one...
-
@RaceProUK said in The Abyss:
Assuming the code file is properly formatted, of course.
If it is my code, it is. Because CDO.
-
The more complex part is identifying what the start of a function looks like
Easy in VB.
[public|private] [sub|function]
-
-
I was asking about identifying function length
For C / C++ and friends,
clang-tidy
, and more specifically itsreadability-function-size
check will do it for you.It's a good tool overall, tbh.
-
-
I was asking about identifying function length
For C / C++ and friends,
clang-tidy
, and more specifically itsreadability-function-size
check will do it for you.It's a good tool overall, tbh.
I'm still of the opinion that
clang
is a rather unfortunate name as it always reminds me of this:
-
@Rhywden It's not as bad as
grunt
-
@RaceProUK At least the guys behind snort are fully aware of alternate meanings :)