5 ms·
Clang vs. GCC – code coverage checking
- mattiemass 11y agoI love stuff like this. Short, understandable.
- feylikurds 11y agoDear God, now I remember why I do not program in C++ anymore (Go and C# all the way!). That pre-11 code looked awful. If networking was nicer, I might actually start considering recoding some of my projects in C++.
- nly 11y agoIt's hard to say what he was trying to accomplish, but he probably could have written something like this. auto index = std::distance (begin(replicas), std::find(begin(replicas), end(replicas), my_ip)); return (replicas.size() == index ? -1 : index);
- pavanky 11y agoThat's a bit harder to read isn't it? I think finding the location in first line and using distance in the ternary operator makes it more readable.
- dave2000 11y agoIf you have £40 or so, and a few evenings free, get the C++11 version of the Stroustrup programming language book and see what's changed. Modern C++ looks entirely different to older C++. Templates still a bit scary, so learn them or ignore them.
- feylikurds 11y agoYes, but are there still tons of boilerplate? Or is there a 11/14/17 library that incredibly decreases the amount of code needed? For example a HTTP listener with routing?
- techprotocol 11y agoA good way to represent a branch coverage miss.
- notanote 11y agoAm I reading this right? He says he is comparing clang 3.8, which is a month old, to gcc 4.8, which branched over 3 years ago. I would rather see what gcc 6 does with this. That release should happen in a month or so.
- feylikurds 11y agoVery good point. I missed that.
- bubuga 11y agoI wouldn't read too much into the article. It's just a blog post of a dude reporting what he saw when he recompiled his code with a different compiler.
- Sanddancer 11y agoAye, but it shows something important. Testing your work with other toolchains and toolings can help discover weaknesses not only in your code, but in the rest of your tooling. Strength in numbers is useful.
- plorkyeran 11y agoThe only gcov-related change listed in the 4.9, 5 and 6 release notes is the addition of a new tool, so I wouldn't expect there to be meaningful changes. Regardless, I think the author's conclusion is overly specific and really should have just been "trying all of the various tools for doing something is useful even if they're theoretically comparable".
- rkday 11y agoThanks for pointing out how old GCC 4.8 is! You're right that a comparison against a later version of GCC is fairer - I've tested with GCC 5.3 (the latest I can easily get) and updated the blog post. (5.3 doesn't spot the missing coverage either.)
- notanote 11y ago
- bla2 11y ago"Build your code with more than one compiler" was good advice 20 years ago, and is still good advice today :-)
- drewcrawford 11y agoI need to ask a stupid question. What does one do with code coverage data? Like, I know what it is. What I'm asking is, on what occasion would the presence of code coverage data be more useful than stepping through the code in a debugger. What is something you do differently having this data than not? Like, is there a code review gate that forbids the code coverage figure to go below 80%? Or do developers consult the reports in a self-motivated way for some reason? Regularly? What is the step between "collect code coverage reports" and "profit"? We recently got this feature in our compiler, and I guess it seems obvious to everyone why to use it, but I must have missed that day in class. So everybody's really excited to create the report, but I can't figure out what they do with it afterward that explains the whole exercise.
- danpat 11y agoRun your test suite, look at the code coverage report, find out which bits of your code doesn't get exercised by the test suite, become aware that changes in those bits of your code probably won't trigger any failing tests if they introduce breakage.
- cornstalks 11y agoSometimes there's a disconnect between what you think you're testing and what you're actually testing. After writing a unit test, I like to look at the code coverage analysis for that unit test and see if it actually tests the code that I think it tests. After seeing the analysis, sometimes I realize I'm not testing for a weird corner case that I should be. It also slightly gamifies unit testing because there's something slightly satisfying in seeing 100% code coverage (though it's important to remember that 100% code coverage doesn't necessarily mean your tests are perfect or test all the conditions you should be).
- wglb 11y agoCode coverage is simple a measure of the amount of the code touched by your tests. It doesn't tell you the quality of effectiveness of the tests. Only what code got executed during your tests.
- etwigg 11y ago
- yonayona 11y agoplease look http://www.expcov.com http://www.expcov.com