http://asawicki.info/ Programming, graphics, games, media, C++, Windows, Internet and more...
Recently I've played a little bit with CppDepend - a commercial static code analysis tool for C++. Windows and Linux versions are available and you can download 14-days trial version. You can find lots of information about the program on their website, including screenshots, sample reports, and cases studies of Ogre3D and Irrlicht game engines. Here is my brief review.
First thing you have to do is to create a CppDepend project. You can add Visual Studio solutions to it and set parameters about what reports you want. Alternatively, if you don't have one beacuse e.g. you use makefiles, you can use separate tool - ProjectMaker - to manually create and save some virtual .sl "solution" that enlists source files and directories to analyze.
Then the program analyzes your code (internally using Clang) and builds a database about it. It generates report in HTML format, as well as allows browsing gathered data interactively inside the program (or inside Visual Studio if you install appropriate AddIn). Here you can see how it looks like for some of my code, combined The Final Quest 7 and CommonLib. First of all, you can browse tree of projects, namespaces, classes and methods:
A HTML raport is generated with the list of found issues:
You can visualize different kinds of relationships like inheritance or just using one type by another as a graph:
Another way to visualize dependencies is matrix:
Yet another view mode is treemap. Here I displayed methods (grouped in classes and modules) where size of a method is dependent on number of lines of code.
You can perform simple search and sorting of projects, namespaces, types, methods and files by name, size and different other metrics. Matched items are highlighted on the treemap.
Finally, you can issue complex queries using CQLinq - a query language based on C# LINQ syntax. Embedded query editor is available with syntax highlighting, autocompletion and immediate query output as you type.
So what kinds of data does the program gather from your code? A lot of. Even such simple thing as number of lines of code is calculated intelligently. Instead of text-based, these are logical LOC, which count sequence points in code, so they are independent of coding style, like braces placement or spanning function call on several lines of code.
I didn't mess with code metrics before, so it was interesting for me to read what does it mean for a piece of code to be "stable" or "abstract". It turns out that the code is stable if its types are used by a lot of types of third-party modules. On the other hand, code is abstract when it contains a lot of abstract classes and interfaces. Code that is stable but not abstract can be painful to modify. Code that is not stable and very abstract is useless. Sounds like an interesting idea :)
Another interesting metric is Cyclomatic Complexity. It is basically a number of decision that can be taken in a function, that is number of: if, while, for, case, default, continue, goto, catch etc. Lack of Cohesion Of Methods (LCOM) is yet another metric. It can indicate quality of a class. It is low when almost every methods in the class uses every field, which is good. It is high when, for example, every method uses only one field (like when class has only getters and setters), which is bad.
Based on these metrics (and many others) and some predefined rules, a list of issues found in the code is enlisted in the report. Some of them are very valuable, some not so much. For example, code matching the rule "Constructor should not call a virtual methods" is obviosly a bug or at least a bad practice. But the rule "Fields should be declared as private" seems a little too restrictive, especially as it matches also globals like const float PI = 3.14.
Generally, it feels great to have analysis based on both physical aspect (like directory structures, source files, comments) and logical aspect of the code (like class inheritance, public versus private, number of nested loops). It's also great that the program analyzes code on all levels, from whole solution depending on external (and possibly unknown) code like Windows.h, through namespaces, classes and methods, down until analyzing code inside functions, counting number of conditions, loops, local variables and analyzing which classes and methods are used by which.
Static code analysis tool like CppDepend is not one of the tools necessary for programming, like editor, compiler or debugger. But I believe it can be useful in at least following applications:
When thinking about a conclusion, I have this thought based on some blogs posts I've read recently (here is the first one, unfortunately I can't find the other one right now) that there is a spectrum of different types of programmers. On one side, there are these very "good", rockstar programmers who are not as good at teamwork and instead of solving real practical problems, they play around with code, talk about theory (whether algorithms or language standard) and write so sophisticated code (e.g. with elaborate C++ template tricks) that it is hard to read and maintain for others. They don't bother to give their variables some meaningful names or split their code into clear modules and classes. On the other side of the spectrum there is the growing number of bad programmers who graduate computer science because they were told to do so (with a promise for good money, lots of jobs or anything) and have no real talent, passion or even basic willingness to learn this profession. They only glue their code using ready frameworks, design patterns and code found on Google using Ctrl+C Ctrl+V. I can see clear relationship between this spectrum and the seriousness with which we take reports about code metrics like these genetared by CppDepend. I also believe that in both cases the best approach lies somewhere in the middle.
Appendix: Clang Rocks! is an interesting article by Issam Lahlali, CppDepend lead developer, that explains how they use Clang frontend to analyze C++ code in their product.
|beautiful things www.rayban.org.es to www.ray-ban-outlet.us.com read more, www.michael-kors.net.co look www.tnf-jackets.us.com for www.nike-schuhe.com.de a long www.nike-roshe-run.com.es time, www.toms--outlet.com.co I www.abercrombieand-fitch.ca felt www.basketballshoes.com.co closer www.ugg-boots.ca to www.uggboots.com.de reality www.oakleyoutlet-online.us.com very www.hogan.com.de far away, www.airmax-2015.org life www.uggsoutlet.com.co is short, www.michaelkorsoutletonline-sale.us.com if www.beats-headphone.com.co put www.cheap-jordans.net too www.swarovskicanada.ca much www.cheapoakley-sunglasses.in.net time www.louis-vuitton-australia.com.au is www.tiffany-und-co.de spent on www.mcm-bags.in.net practical www.tocoachoutlet.com things, really www.ugg-boots-australia.com.au is www.ugg-australia.com.de a www.ralph-lauren.com.au waste www.pandorajewelry.top of www.nike.org.es life, www.thenorthface.com.de but some www.eyeglassesonline.us.com things, www.nike--freerun.co.uk but www.canadagooses-2016.com if www.longchamp.com.co the www.gucci-taschen-outlet.de raw flavor, www.outlet-burberry.net.co leisure www.nike-shoes-canada.ca goods airmax.shoesoutlet.us.com for www.oakleys-sunglasses.us.com gossip, www.marcjacobs.us.com so www.hermes-outlet.com.co I www.asicsgels.de love www.chanel-bags.com.co romantic www.christianlouboutinshoesoutlet.org dreamer, www.rolexwatches-canada.ca but www.timberlandbootsoutlet.us.com I www.ray-bansunglasses.net love www.wedding--dresses.ca real www.katespadeoutlet.gb.net life.Day www.tomsoutletonline.net in www.nikefactory.org a hurry, took www.iphone-cases.net.co all www.bottega-veneta.us.com the www.p90xworkout.us.com joy www.rolex-watches.us.com and www.truereligion-outlet.com.co sadness, www.hollisteronlineshop.com.de a www.replica-watches.com.co lot www.nikeshoesoutlet.org.uk of www.michael-kors-taschen.com.de things, not www.soccer-shoes.us.com enough www.giuseppe-zanotti.net time www.louisvuitton-outlet.com.co to www.nike-tnrequinpascher.fr recall, www.michaelkorsoutlet.ar.com Chaoyang www.polo-ralph-lauren.de July, www.coach-outletonline.net.co early www.ralphs-lauren.co.uk June already www.juicycoutureoutlet.net.co covered www.longchamp.com.de confused. www.jimmy-choos.com Season www.toryburchsale.com.co removed, www.nike-skor.com.se landscape www.prada-handbags.com.co transformation, www.christian--louboutin.in.net the so-called forever www.cheapoakley-sunglasses.com always www.designer-handbagsoutlet.us.com far-fetched, www.ralphlaurenoutlet-online.us.com time, www.mizuno-running.net not www.thomas-sabos.org.uk to www.nikerosherun.us be www.burberry2016.co.uk squandered, www.nfl-jersey.us.com the www.omegarelojes.es true meaning of life www.truereligion-outlet.us.org is www.michael-kors.com.co to www.cheaprayban.com.co enjoy the good www.michaelkors.so in www.tommyhilfiger.net.co the www.rosheruns.us flat, www.christianlouboutin.org.uk I www.mcmbags.net Dimei airhuarache.shoesoutlet.us.com fireworks, www.tiffanyandco-canada.ca also airmax.misblackfriday.com read www.rayban-sunglassesoutlet.co.uk the www.louisvuittons.com.co leisure, www.moncler-outlet.us.org with www.raybans-sunglassesoutlet.in.net a www.lauren-ralph.co.uk touch www.ralph-laurenoutlet.ca of www.converse-shoes.net ink, www.louis-vuittonoutletcanada.ca painting www.nike-rosherun.nl a www.nike-air-max.com.de thin www.ugg-bootsclearance.com clear www.coach-factoryyoutletonline.net Huan, www.toms-shoes.net.co look www.coachoutlet-online.com.co lush www.michaelkors-uk.org.uk green, www.burberryoutlet2016.us.com covered www.chi-flatiron.us.com with www.nikemercurial.in.net mottled www.michaelkors-outlet-online.com.co wall. www.oakley.org.es This www.toms-shoes.com.co July, I www.michaeljordan.com.de kept www.woolrich-clearance.com the www.mcmsworldwide.com book's www.burberry-handbagsoutlet.com.co swoosh; www.beats-by-dre.com.co this www.oakleys-glasses.us.com July, www.hollister-abercrombie.com.se I www.jordan-shoes.com.co dream www.montblanc--pens.in.net in www.tommyhilfigeroutlet.in.net Lijiang; www.nike-air-max.ca this www.burberrybags-outlet.com July, and has www.burberryoutlet-sale.in.net been well, not www.supra-shoes.org made www.new-balance.ca sad.If www.oakley-sunglasses.mex.com you www.coach-factory.in.net can www.levisjeans.com.co do www.lululemon-australia.com.au if www.christian-louboutin-shoes.ca a www.tory-burchshoesoutlet.net light www.celine-bags.org breeze www.tiffany-andco.us.com right www.louboutin.jp.net woman, www.hollister.us.org placed www.oakley.com.de in the www.designerhandbagsoutlet.net.co text www.beatsbydrdre.co.com soul, www.valentino-shoesoutlet.us.com written www.coco-chanels.us.com imprint of www.ghd-hairstraightener.net life, write www.longchamp-handbagsoutlet.us.com thin www.nike-air-max.com.se cool www.adidas.com.se and www.cheap-oakleyglasses.us.com clear www.thomas-sabo.com.de Huan, www.new-balance-schuhe.de occasionally www.ferragamoshoes.in.net write www.soccer-shoesoutlet.com love, www.nike-shoesoutlet.us.com but www.babyliss-pro.us.com never uggaustralia.misblackfriday.com give www.louis-vuittonblackfriday.com love, www.michael--kors.us.com keep www.tomsshoes-outlet.us.com a www.swarovski--uk.me.uk clear www.replicarolex-watches.us.com gel www.calvin-kleins.us.com Bay, www.retro-jordans.com look www.fashionclothes.us.com for www.omega-watches.us.com a www.reebok.com.de parts www.pulseras-pandora.com.es of www.burberrys-outlet.co.uk the www.timberlandshoes.net.co peace, www.hollisterclothingstore.org the www.rosherun.org.uk joy www.the-northface.net.co and www.bottegaveneta-bagsoutlet.com sorrow www.jordanretro.org of www.pandorajewellery.com.au all www.michael-korshandbags.org.uk his www.harrods-london.co.uk writings, www.longchamp-bags.us.com and www.longchampoutlet.com.co text www.montres-pascher.fr only www.vans-shoes.net affair has www.tiffanyand-co.net.co nothing www.uggboots.net.co to do www.toms-outlets.us.com with www.rayban.co.nl the www.chanelhandbags.net.in other.Morning www.ralphlauren-polos.com.co time, www.michael-kors-outlet.us.org with www.tiffany-jewelry.net a www.polo-outlets.com.co tranquil www.uggs-onsale.net and www.the-northface.com.co contented www.converse.net.co Zen cloud www.newbalance-outlet.org water, www.christianlouboutinoutlet.net.co eyes www.guccioutlet-sale.in.net closed, www.nikefree-run.org.uk the www.newbalance.com.es heart www.kate-spade.in.net distant www.truereligionjeans.net.co exile, www.michael-kors-handbags.us.com Wind www.nike-maxfr.com and www.chiflatiron.net.co Smoke www.instylers.us.com curl www.louis--vuitton.org.uk in www.nike-airmaxinc.co.uk the www.raybans.us.org mountains, www.the-north-face.ca such www.adidas--canada.ca as Dai, www.nikefree5.net ups www.true-religion.com.co and www.toms-shoesoutlet.net downs, www.giuseppezanotti.com.co indeed, www.juicycouture.com.co like a www.abercrombie-hollister.nl thread, www.airhuarache.co.uk the www.nikeair--max.fr ups www.soft-ballbats.com and downs www.coco-chanel.com.de of www.ray--ban.ca life, www.christian-louboutinshoes.com.co with www.swarovskijewelry.com.co long www.oakleysunglasses-cheap.in.net Qingyuan www.nikeskos.dk . Flowers www.air-huarache.co.uk followed www.newoutletonlinemall.com the www.marc-jacobs.us.com road, www.rayban.com.de facing www.vans-schuhe.com.de the www.yoga-pants.ca sun www.coach-factoryoutlet.net.co slowly www.cheapuggboots.us.com forward, www.longchamps.us.com then the www.beatsbydre.com.co mind www.weddingdressesuk.org.uk is www.louisvuitton.so calm, www.adidas.org.es quiet www.uhren-shop.com.de as www.airmax-90.org the www.poloralphlaurenoutlet.net.co lake, www.uggs.in.net the www.toryburchoutlet-sale.us.com water www.tommy-hilfigeroutlet.com peach, flower www.abercrombie-and-fitch.us.com with www.nike-air-max.com.au water, just www.hollister-clothing.in.net like www.cheap-raybans.com the www.adidas-schuhe-online.de fate www.oakley--sunglasses.com.au of www.thenorthfacejackets.net.co this www.adidas-superstar.de world, www.burberry-outletonlinesale.in.net do not www.oakleysunglass-outlet.net ask why, www.converse.com.de regardless www.bcbg-max-azria.ca of www.louisvuitton.jp.net come www.guccishoes-uk.co.uk and www.cheap-nike-shoes.net go, www.ralphlaurenpolos.in.net only flowers www.oakley-sunglasses-canada.ca need www.toryburch-sandals.in.net to www.tommy-hilfiger.co.nl remember www.michaelkorsoutlet-online.ar.com Lu www.polooutlets-store.com Qing, Yue www.edhardy.us.org possessor www.nike-schoenen.co.nl of www.vans-shoes.co.uk the www.mk-outlet.us.com green www.tomsoutlet-online.com heart, www.maccosmetics.net.co cool count. www.ralph-laurens.org.uk Sunlight www.ugg-uggboots.net penetration mist, www.pumaonline-shop.de alluding www.abercrombie-fitchs.us.com on www.hermesbirkin-bag.net the www.ralphslauren-outlet.co.uk lake, www.nikestore.com.de the www.louis-vuitton-taschen.com.de water green, www.replica-handbags.net.co clear, www.pumashoes.in.net sparkling, on www.swarovski-online-shop.de the www.burberry-handbags2016.in.net beach, www.michaelkorsbags.us.org there www.thenorth-faces.co.uk are birds www.coachblackfriday.com flying www.pradaoutlet.com.co over www.canada-goosesjackets.us.com from www.hermesbags.jp.net time www.tommy-hilfiger.com.de to time, www.eyeglassframes.in.net the sky www.barbour-factory.com blue and www.air-max.com.de empty, www.burberryonlineshop.de with nike.shoesoutlet.us.com a www.pandora-charms-canada.ca quiet www.maccosmetics.gr.com life www.converse-shoesoutlet.com after www.ralphlaurenonlineshop.de ups www.cheapjerseys.com.co and www.cheapjerseys.us.org downs, www.coachoutletstore.net.co this www.uggs.co.nl time www.ray-banocchiali.it the www.handbagsoutlet.net.co heart supra.shoesoutlet.us.com is close www.mkoutletonline.us.com to www.ralphlaurenoutletonline.us.org nature, www.burberryoutlet-canada.ca without www.newbalance-shoes.org the www.adidas-superstar.nl slightest ripples, www.mcmhandbags.com.co content www.michaelkors.co.nl with www.hollisters-canada.ca this www.mmoncler-outlet.com quiet www.michaelkors.com.se and www.horloges-rolex.nl peaceful. www.tommy-hilfiger-online-shop.de An www.nike-air-max.us end, www.michael-kors-outlet-online.us.org wins the www.nike-roshe-run.de snow www.mcm-handbags.org lotus, www.michael-kors-canada-outlet.ca world www.ferragamo.com.co clarity, www.barbour-jacketsoutlet.com years www.rayban-wayfarer.in.net of www.rayban-sunglasses.us.org silence, www.thejoreseproject.com the heart www.guccishoes.com.co is www.nike-air-force.de also www.cheap-baseballbats.net safe.Time, very www.burberry-outletstore.net long. www.adidasshoes.top I www.nike-huarache.nl know, www.jimmy-chooshoes.com I www.michael-kors-australia.com.au can www.ralphlaurenoutlet.us.com stay www.tiffany-andco.com.au in my www.nikefree-run.net mind www.gucci-outletstore.com there www.nikestore.us are www.timberlands-paschere.fr limitations, www.jordanrelease-dates.us.com not www.oakley-outletstore.in.net the www.ghdhair-straighteners.co.uk majority, can www.ralphlauren-polos.co.uk only www.nike-free-run.de rely www.bcbg-dresses.com on www.salomon-schuhe.com.de these www.airjordans.us words www.swarovski-australia.com.au to www.pandora.com.de memory.Time, www.asics-outlet.us.com is very www.kate-spade.gb.net short. www.zxcoachoutlet.com I www.prada-shoes.com.co understand, www.ralphlaurenepolo.com you www.oakleyoutlet.ar.com can www.prada.com.de never www.burberrys-outlet2016.com forget www.yoga-pants.net.co so www.ugg-boots.us.org little, www.cheapshoes.com.co so www.christianlouboutinshoes.jp.net I www.rolexwatchesforsale.us.com was www.northfaceoutlet.com.co in www.coachoutletstore-online.com.co such a www.polos-ralphlauren.us.com manner www.gucci-shoes.net so www.pandora-charms.org.uk as www.uggsaustralia.com.co to www.guccihandbags.net.co leave some www.tommy-hilfiger-canada.ca more.Youth, is www.guccishoes.in.net very long. www.cheapmichaelkors.us.org In www.salvatoreferragamo.in.net life, shiny www.swarovski-crystal.us.com people, www.scarpe-hoganoutlets.it in www.nikeair-max.es fact, www.insanity-workout.us.com that www.bebeclothing.in.net a www.coachhandbags2016.us.com figure, www.louisvuitton-outlets.us how www.cheap-michaelkors.com the www.abercrombie-kids.us.com passage of www.coach-purseoutlet.net time, www.pradahandbags.net.co or the www.rolex-watch.me.uk whole www.the-northfacejackets.us.com dazzling Love.Youth, www.michael-kors.com.es is www.burberry-outlet.net.co very www.lululemoncanada.ca short. www.ralphlaurenoutletonline.in.net In www.longchamphandbagsoutlet.net life, flickering days www.abercrombie-fitchsale.com |