{"id":578,"date":"2014-04-27T00:41:11","date_gmt":"2014-04-27T00:41:11","guid":{"rendered":"http:\/\/blog.wholetomato.com\/?p=578"},"modified":"2019-05-03T17:28:51","modified_gmt":"2019-05-03T21:28:51","slug":"sort-lines","status":"publish","type":"post","link":"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/","title":{"rendered":"Sorting One&#8217;s Code"},"content":{"rendered":"<p>Visual Assist has a plethora of features, and it&#8217;s difficult to know them all. It&#8217;s an even greater challenge to use all of them at every opportunity.<\/p>\n<p>We had\u00c2\u00a0one user, Tom, write\u00c2\u00a0recently that his &#8220;very small favourite feature&#8221; in Visual Assist is Sort Lines. Sort lines, we wondered.\u00c2\u00a0We don&#8217;t often sort\u00c2\u00a0when writing code. After a bit of\u00c2\u00a0thought, we\u00c2\u00a0acknowledged that if one does need to sort, however\u00c2\u00a0infrequently, a built-in sort can be very\u00c2\u00a0handy.<\/p>\n<p>In this blog post, I touch on a few use cases for Sort Lines, some of which might resonate with you.<\/p>\n<p>If you have enums not dependent on order, consider sorting them for readability. Sort all or a subset, remembering to exclude a count that must be the last item.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"594\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortlinesenum\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?fit=204%2C332&amp;ssl=1\" data-orig-size=\"204,332\" 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=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?fit=184%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?fit=204%2C332&amp;ssl=1\" class=\"alignnone size-full wp-image-594\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?resize=204%2C332&#038;ssl=1\" alt=\"\" width=\"204\" height=\"332\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?w=204&amp;ssl=1 204w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenum1.png?resize=184%2C300&amp;ssl=1 184w\" sizes=\"(max-width: 204px) 100vw, 204px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Select your lines and\u00c2\u00a0invoke sort from the Tools submenu of VAssistX:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"581\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortlinesmenu\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?fit=425%2C246&amp;ssl=1\" data-orig-size=\"425,246\" 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=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?fit=300%2C174&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?fit=425%2C246&amp;ssl=1\" class=\"alignnone size-full wp-image-581\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?resize=425%2C246&#038;ssl=1\" alt=\"\" width=\"425\" height=\"246\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?w=425&amp;ssl=1 425w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?resize=300%2C174&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesmenu.png?resize=360%2C208&amp;ssl=1 360w\" sizes=\"(max-width: 425px) 100vw, 425px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Sorting is always alphabetic, and done in place.\u00c2\u00a0Only complete lines of a selection are sorted; sort Lines ignores the line with the text caret\u00e2\u20ac\u201dwhether or not the line\u00c2\u00a0includes any\u00c2\u00a0selected text.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenumafter.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"599\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortlinesenumafter\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenumafter.png?fit=201%2C268&amp;ssl=1\" data-orig-size=\"201,268\" 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=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenumafter.png?fit=201%2C268&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenumafter.png?fit=201%2C268&amp;ssl=1\" class=\"alignnone size-full wp-image-599\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesenumafter.png?resize=201%2C268&#038;ssl=1\" alt=\"\" width=\"201\" height=\"268\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>In unmanaged code, \u00c2\u00a0#defines are sometimes good\u00c2\u00a0candidates for a sort.\u00c2\u00a0If circumstances allow, sort before assigning values to your macros. Sorting operates\u00c2\u00a0at the line level, so don&#8217;t attempt a sort\u00c2\u00a0if your macros and their comments span multiple lines.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"604\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortlinesdefinesbefore\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?fit=498%2C112&amp;ssl=1\" data-orig-size=\"498,112\" 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=\"sortLinesDefinesBefore\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?fit=300%2C67&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?fit=498%2C112&amp;ssl=1\" class=\"alignnone size-full wp-image-604\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?resize=498%2C112&#038;ssl=1\" alt=\"\" width=\"498\" height=\"112\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?w=498&amp;ssl=1 498w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?resize=300%2C67&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?resize=360%2C81&amp;ssl=1 360w\" sizes=\"(max-width: 498px) 100vw, 498px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesbefore.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"603\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortlinesdefinesafter\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?fit=489%2C108&amp;ssl=1\" data-orig-size=\"489,108\" 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=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?fit=300%2C66&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?fit=489%2C108&amp;ssl=1\" class=\"alignnone size-full wp-image-603\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?resize=489%2C108&#038;ssl=1\" alt=\"\" width=\"489\" height=\"108\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?w=489&amp;ssl=1 489w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?resize=300%2C66&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortlinesdefinesafter1.png?resize=360%2C80&amp;ssl=1 360w\" sizes=\"(max-width: 489px) 100vw, 489px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>Finally, if you are confident your C\/C++ headers don&#8217;t need to be included in order, sort them so they are easier to browse.<\/p>\n<p><img decoding=\"async\" data-attachment-id=\"580\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortheadersbefore\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersbefore.png?fit=274%2C160&amp;ssl=1\" data-orig-size=\"274,160\" 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=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersbefore.png?fit=274%2C160&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersbefore.png?fit=274%2C160&amp;ssl=1\" class=\"alignnone size-full wp-image-580\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersbefore.png?resize=274%2C160&#038;ssl=1\" alt=\"\" width=\"274\" height=\"160\" data-recalc-dims=\"1\" \/><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersafter.png?ssl=1\"><img decoding=\"async\" data-attachment-id=\"579\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/sort-lines\/sortheadersafter\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersafter.png?fit=265%2C156&amp;ssl=1\" data-orig-size=\"265,156\" 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=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersafter.png?fit=265%2C156&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersafter.png?fit=265%2C156&amp;ssl=1\" class=\"alignnone size-full wp-image-579\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2014\/04\/sortheadersafter.png?resize=265%2C156&#038;ssl=1\" alt=\"\" width=\"265\" height=\"156\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>If you find yourself sorting manually, however infrequently, remember\u00c2\u00a0that Visual Assist makes the task simple. Our user Tom uses\u00c2\u00a0Sort Lines so much\u00c2\u00a0he assigned\u00c2\u00a0a shortcut to\u00c2\u00a0the command.<\/p>\n<p>Finally,\u00c2\u00a0if you have a different use case for Sort Lines, we&#8217;d love to hear about it. Please share your case in a comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Assist has a plethora of features, and it&#8217;s difficult to know them all. It&#8217;s an even greater challenge to use all of them at every opportunity. We had\u00c2\u00a0one user, Tom, write\u00c2\u00a0recently that his &#8220;very&#8230;<\/p>\n","protected":false},"author":28485711,"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-578","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-9k","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/578","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\/28485711"}],"replies":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/comments?post=578"}],"version-history":[{"count":24,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/578\/revisions"}],"predecessor-version":[{"id":620,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/578\/revisions\/620"}],"wp:attachment":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/media?parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/categories?post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/tags?post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}