The Abyss



  • @dkf said in 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...).



  • @Zecc said in The Abyss:

    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.


  • Discourse touched me in a no-no place

    @remi said in The Abyss:

    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.


  • Discourse touched me in a no-no place

    @PleegWat said in The Abyss:

    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.


  • SockDev

    @dkf said in The Abyss:

    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.



  • @dkf said in The Abyss:

    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.



  • @dkf said in The Abyss:

    @PleegWat said in The Abyss:

    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.



  • @dkf said in The Abyss:

    @remi said in The Abyss:

    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...


  • Discourse touched me in a no-no place

    @RaceProUK said in The Abyss:

    Assuming the code file is properly formatted, of course.

    If it is my code, it is. Because CDO.


  • kills Dumbledore

    @dkf said in The Abyss:

    The more complex part is identifying what the start of a function looks like

    Easy in VB.

    [public|private] [sub|function]
    

  • area_deu

    @RaceProUK said in The Abyss:

    @dkf All I can think of now is
    0_1485524168227_upload-e25364a8-ed6c-4d77-9f38-fc2df65c3277

    Needs more molten cheese :yum:



  • @remi said in The Abyss:

    I was asking about identifying function length

    For C / C++ and friends, clang-tidy, and more specifically its readability-function-size check will do it for you.

    It's a good tool overall, tbh.



  • @aliceif said in The Abyss:

    Needs more molten cheese

    A nice garlic butter sauce would work too!



  • @tufty said in The Abyss:

    @remi said in The Abyss:

    I was asking about identifying function length

    For C / C++ and friends, clang-tidy, and more specifically its readability-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:

    0_1487109166184_upload-90d308ff-5d60-4af4-a214-a631fc5ff89f


  • SockDev

    @Rhywden It's not as bad as grunt



  • @RaceProUK At least the guys behind snort are fully aware of alternate meanings :)


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.