{"id":838,"date":"2014-11-23T01:43:08","date_gmt":"2014-11-23T01:43:08","guid":{"rendered":"http:\/\/blog.wholetomato.com\/?p=838"},"modified":"2014-11-23T01:43:08","modified_gmt":"2014-11-23T01:43:08","slug":"tools-to-understand-new-code-find","status":"publish","type":"post","link":"https:\/\/stage.wholetomato.com\/blog\/tools-to-understand-new-code-find\/","title":{"rendered":"Tools to understand new code: Find"},"content":{"rendered":"<p>In <a href=\"https:\/\/stage.wholetomato.com\/blog\/2014\/10\/27\/tools-to-understand-new-code-go-to\/\">my previous post<\/a> as a guest contributor, I talked about moving between declaration and implementation of various symbols: methods, classes, variables&#8230; and even include files. The functionality\u00c2\u00a0helps a lot, but there are other tools in Visual Assist that we definitely need to know. This time, let&#8217;s have a look at some\u00c2\u00a0find commands\u00c2\u00a0in\u00c2\u00a0Visual Assist.<\/p>\n<p>As in my last post, I will use\u00c2\u00a0<a href=\"http:\/\/irrlicht.sourceforge.net\/\" target=\"_blank\">Irrlicht Engine<\/a>\u00c2\u00a0as my example project.<\/p>\n<p><strong>Find References<\/strong><\/p>\n<p>With <em>Go To<\/em>,\u00c2\u00a0we can jump\u00c2\u00a0from declaration to implementation smoothly. This is nice, but unfortunately, life is not that easy. Usually when we see an interesting variable or function, we would like to see not only its declaration or implementation, but how and where is it used.<\/p>\n<p>Previously, we were curious about <code>MaxAngleDegrees<\/code> from <code>CParticleBoxEmitter.cpp<\/code>. We know than it&#8217;s a 32-bit integer variable used to generate rotations. But, where it is actually initialized?<\/p>\n<p>With Visual Assist, press Shift+Alt+F (the default\u00c2\u00a0shortcut for its\u00c2\u00a0<em>Find References<\/em>) and you will see a dialog\u00c2\u00a0like this:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"839\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/tools-to-understand-new-code-find\/find_maxang\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?fit=1048%2C334&amp;ssl=1\" data-orig-size=\"1048,334\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"find_maxang\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?fit=300%2C96&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?fit=1024%2C326&amp;ssl=1\" class=\"alignnone size-full wp-image-839\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?resize=660%2C210&#038;ssl=1\" alt=\"find_maxang\" width=\"660\" height=\"210\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?w=1048&amp;ssl=1 1048w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?resize=300%2C96&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?resize=1024%2C326&amp;ssl=1 1024w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?resize=768%2C245&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_maxang.png?resize=360%2C115&amp;ssl=1 360w\" sizes=\"(max-width: 660px) 100vw, 660px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>The window\u00c2\u00a0lists places where our variable is used. It seems that the variable is loaded from a settings file.<\/p>\n<p>The basic list is, of course, nothing special\u00e2\u20ac\u201dVisual Studio has a similar feature. But with Visual Assist, we have more benefits:<\/p>\n<ul>\n<li>You can see a context of each\u00c2\u00a0line in a tooltip<\/li>\n<li>You can view only\u00c2\u00a0Read or Write references<\/li>\n<li>As with most Visual Assist tools, it works faster than the equivalent in Visual Studio. (Also, I&#8217;ve found that the results with Visual Assist are a bit more narrow.)<\/li>\n<\/ul>\n<p>We can extend our search and go further:<\/p>\n<ul>\n<li><code>MaxAngleDegrees<\/code> is deserialized in <code>CParticleBoxEmitter::deserializeAttributes<\/code><\/li>\n<li>This method is called from <code>CParticleSystemSceneNode::deserializeAttributes<\/code><\/li>\n<li>It&#8217;s also polymorphic and might be called from <code>CSceneLoaderIrr::readSceneNode<\/code><\/li>\n<li>&#8230;<\/li>\n<\/ul>\n<p>We can even track the whole system of loading scene nodes. We can now see the flow of this functionality. Without\u00c2\u00a0<em>Find References<\/em>,\u00c2\u00a0it would be very problematic.<\/p>\n<p>Tip: You can also use <em>Find References in File<\/em> to, as the name suggests, see references to a symbol in the file you are actually in.<\/p>\n<p><strong>Find Symbol<\/strong><\/p>\n<p>Finding references for a given symbol is very useful, but what if you do not know an\u00c2\u00a0exact name? Maybe you just have some basic idea of what you want to find.<\/p>\n<p>For instance, in Irrlicht Engine, we might want to see the implementation and an interface of a scene manager. <em>Find References<\/em> would not work well this time because we don&#8217;t have a reference. You could use the normal search box of Visual Studio, but you will probably\u00c2\u00a0end up with too many\u00c2\u00a0symbols and lines to check.<\/p>\n<p>In this instance, you can use <em>Find Symbol<\/em> (Shift+Alt+S by default) in Visual Assist. <em>Find Symbol<\/em>\u00c2\u00a0opens\u00c2\u00a0a dialog box with\u00c2\u00a0all symbols from the current solution (and even third-party libraries!) I typed &#8220;manager scene&#8221; in the edit control of my\u00c2\u00a0dialog and got the following:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"840\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/tools-to-understand-new-code-find\/find_mgr\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?fit=822%2C420&amp;ssl=1\" data-orig-size=\"822,420\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"find_mgr\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?fit=300%2C153&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?fit=822%2C420&amp;ssl=1\" class=\"alignnone size-full wp-image-840\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?resize=660%2C337&#038;ssl=1\" alt=\"find_mgr\" width=\"660\" height=\"337\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?w=822&amp;ssl=1 822w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?resize=300%2C153&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?resize=768%2C392&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/11\/find_mgr.png?resize=360%2C184&amp;ssl=1 360w\" sizes=\"(max-width: 660px) 100vw, 660px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>As you can see,\u00c2\u00a0&#8220;manager scene&#8221; is related to several different classes. We can double-click\u00c2\u00a0the most interesting object and go to its definition.<\/p>\n<p>The <em>Find Symbol<\/em> dialog supports\u00c2\u00a0more advanced options as well, like searching only in classes (this will skip defines and free functions) or extending your search to files outside your solution.<\/p>\n<p><em>Find Symbol<\/em>\u00c2\u00a0is definitely much more convenient that the common search dialog of Visual Studio.<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>Our tool bag now contains two very important items: <em>Go To<\/em> and <em>Find<\/em>. We can now easily search for various symbols in solutions, easily go to their implementation\/declarations. And\u00c2\u00a0with the Find commands, we are able to search for all occurrences of a given symbol and create a story of how it is used in a\u00c2\u00a0project.<\/p>\n<p><strong>Learn More<\/strong><\/p>\n<p>You can learn more about the Find commands in the documentation for Visual Assist:<\/p>\n<ul>\n<li><a href=\"http:\/\/docs.wholetomato.com\/default.asp?W189\">Find References<\/a><\/li>\n<li><a href=\"http:\/\/docs.wholetomato.com\/default.asp?W194\">Find Symbol in Solution<\/a><\/li>\n<\/ul>\n<p><em>This article was contributed by\u00c2\u00a0Bartlomiej Filipek, who writes\u00c2\u00a0at\u00c2\u00a0<a href=\"http:\/\/www.bfilipek.com\/\" target=\"_blank\">Code And Graphics<\/a>\u00c2\u00a0&#8211;\u00c2\u00a0a technical blog about\u00c2\u00a0C++ and OpenGL.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post as a guest contributor, I talked about moving between declaration and implementation of various symbols: methods, classes, variables&#8230; and even include files. The functionality\u00c2\u00a0helps a lot, but there are other tools&#8230;<\/p>\n","protected":false},"author":66190671,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[672],"tags":[],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-tips-and-tricks"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfhqii-dw","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/users\/66190671"}],"replies":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/comments?post=838"}],"version-history":[{"count":5,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/838\/revisions\/846"}],"wp:attachment":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/media?parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/categories?post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/tags?post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}