[dev] semicolons
I've checked iolanguage.org and noticed that they are calculating the complexity/size of their vm in semicolons instead of number of lines. I think this is a much simpler way to calculate the complexity of a program and can be implemented easily with awk. using sloccount is probably cool, but sloccount is far from perfect, as long as can be tricked by using different indentations. This is why I'm considering other ways to calculate code complexity. And counting semicolons or parenthesys can be a good way to do it. What do you think? $ cat dwm.c | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l 1131 Doing it in C would be even simpler, and we can distribute it as the standard suckless tool for calculating code complexity in C programs. Counting opened parenthesis is also a nice way to check complexity.. so my idea is to write a tool like 'wc', but showing statistical info from source programs. - skip comments, quoted chars (strings, ';') and #if0'd code - count lines - count parenthesis - count semicolons --pancake
Re: [dev] semicolons
On Fri, Nov 18, 2011 at 11:40:10AM +0100, pancake wrote: I've checked iolanguage.org and noticed that they are calculating the complexity/size of their vm in semicolons instead of number of lines. I think this is a much simpler way to calculate the complexity of a program and can be implemented easily with awk. using sloccount is probably cool, but sloccount is far from perfect, as long as can be tricked by using different indentations. This is why I'm considering other ways to calculate code complexity. And counting semicolons or parenthesys can be a good way to do it. What do you think? $ cat dwm.c | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l 1131 Doing it in C would be even simpler, and we can distribute it as the standard suckless tool for calculating code complexity in C programs. Counting opened parenthesis is also a nice way to check complexity.. so my idea is to write a tool like 'wc', but showing statistical info from source programs. - skip comments, quoted chars (strings, ';') and #if0'd code - count lines - count parenthesis - count semicolons --pancake Statistically speaking, it might be best at this point to use a multitude of counting mechanisms, using both line counts and semicolon counts. Anything can be worked around one way or another. For reference, standard benchmark tools also never look at just one thing. -- Roger http://rogerx.freeshell.org/
Re: [dev] semicolons
On 18 November 2011 11:41, Roger rogerx@gmail.com wrote: Anything can be worked around one way or another. For reference, standard benchmark tools also never look at just one thing. Exactly, short of writing a C-parser and doing some heuristic on the syntax tree, you'll just end up missing things anyway. if(5) x = 5, y = 2, apply_layout(NULL), something_else_that_doesnt_use_semi_colons();
Re: [dev] semicolons
On 11/18/11 13:10, Rob wrote: On 18 November 2011 11:41, Rogerrogerx@gmail.com wrote: Anything can be worked around one way or another. For reference, standard benchmark tools also never look at just one thing. Exactly, short of writing a C-parser and doing some heuristic on the syntax tree, you'll just end up missing things anyway. if(5) x = 5, y = 2, apply_layout(NULL), something_else_that_doesnt_use_semi_colons(); should we support code written by bitches?
Re: [dev] semicolons
On 18 November 2011 12:24, pancake panc...@youterm.com wrote: should we support code written by bitches? main(argc, argv) int argc; char **argv; { } // SLOC of two, should be zero #define SEMI ; int main(int argc, char **argv) { int i SEMI for(i = 0 SEMI i argc SEMI i++) printf(argv[%d] = %s\n, i, i[argv]) SEMI return 0 SEMI } // SLOC count of 1, should be much more :P
Re: [dev] semicolons
On 2011-11-18 11:40, pancake wrote: $ cat dwm.c | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l use cpp to deal with the includes, defines, comments. __sloc() { grep -v '^#include.*' $1 | cpp - | grep -v '^#' | grep -v '^$' } sloc() { __sloc $1 | wc -l __sloc $1 | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l __sloc $1 | sed -e 's,(,ROFL\n,g' |grep ROFL |wc -l } worrying about stuff like the next seems tree/forest-y if (error) return printf(boot-head = missed?), -1; btw, anyone recommend a suckless AST tool for C? Patrick
Re: [dev] semicolons
On 11/18/11 14:03, Patrick Haller wrote: On 2011-11-18 11:40, pancake wrote: $ cat dwm.c | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l use cpp to deal with the includes, defines, comments. __sloc() { grep -v '^#include.*' $1 | cpp - | grep -v '^#' | grep -v '^$' } sloc() { __sloc $1 | wc -l __sloc $1 | sed -e 's,;,ROFL\n,g' |grep ROFL |wc -l __sloc $1 | sed -e 's,(,ROFL\n,g' |grep ROFL |wc -l } worrying about stuff like the next seems tree/forest-y if (error) return printf(boot-head = missed?), -1; you can use gcc -E or cpp output to parse btw, anyone recommend a suckless AST tool for C? Patrick i wrote ALT a while ago. its not C specific, but can be used for basic c-like syntaxes. a part from that, parsing C sucks a lot, and the only solution i could imagine is by using tcc or sparse, but both solutions sucks in some way or other. --pancake
Re: [dev] semicolons
On 2011-11-18 13:24, pancake wrote: should we support code written by bitches? KR v1, page 59: for (i = 0, j = strlen(s)-1; i j; i++, j--) { SLoC count? Bitch count? ;)
Re: [dev] semicolons
precisely what is the payoff for nerding out about this? -- # Kurt H Maier