{"id":5666,"date":"2013-02-13T16:04:25","date_gmt":"2013-02-14T00:04:25","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=5666"},"modified":"2013-02-19T11:36:51","modified_gmt":"2013-02-19T19:36:51","slug":"not-all-syntax-coloring-is-created-equal","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2013\/02\/13\/not-all-syntax-coloring-is-created-equal\/","title":{"rendered":"Not all syntax coloring is created equal"},"content":{"rendered":"<p>Syntax coloring for programming languages was originally introduced as a visual aid to assist developers in assessing the syntactical correctness of code. Unlike the squiggly red or green underlines in Microsoft Word colors indicate validation rather than error. So while glancing at a syntax colored stretch of code the usual green hue of comments and reddish string colors enclosed in double quotes quickly instill a sense of the structure to the code. Commands are colored in certain specific colors and indicate that the system is aware of them. <\/p>\n<p>Traditional programming languages, like C\/C++, have only a very few keywords, so the coloring is mostly pretty sparse.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image.png\" width=\"553\" height=\"167\"> <\/p>\n<p><em>Typical C++ code sample in Visual Studio 2008<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>With the introduction of the .NET framework and type reflection, IDEs and editors where suddenly able to color new types of keywords.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image1.png\" width=\"605\" height=\"273\"> <\/p>\n<p><em>Typical C# sample in Visual Studio 2010<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>The first thing you will notice when comparing these two screenshots is that for C# types are now colored as well. <\/p>\n<p>This entire syntax coloring mechanism not only serves as a visual aid when analyzing existing code, it also assists when writing code. Users of modern IDEs and editors have become very accustomed to keywords changing color as you finish the word and hit space.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image_thumb.png\" width=\"130\" height=\"38\"><\/a> <\/p>\n<p><em>typing a cmdlet just before finishing it<\/em><\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image_thumb1.png\" width=\"131\" height=\"43\"><\/a> <\/p>\n<p><em>after finishing the cmdlet<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Most us give pause to typing when we notice that the previous word typed did not change color and become bold as we moved on to the next word. <\/p>\n<p>Now, recently we received an email from a customer complaining that PrimalScript 2012 does not color .NET types in PowerShell. Or type accelerators for that matter. Which is true and once we were reminded of that we immediately went and implemented that feature. It was rolled out in service build 6.5.141. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image4.png\" width=\"417\" height=\"304\"> <\/p>\n<p><em>.NET type and accelerator coloring in PrimalScript 2012<\/em><\/p>\n<p>It was also pointed out to us that the PowerShell V3 ISE does color .NET types and that we should really get moving on this. Not that we needed that additional incentive, but it caused us to give that part of the ISE a closer look.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image5.png\" width=\"378\" height=\"236\"> <\/p>\n<p><em>.NET Type and accelerator coloring in PowerShell V3 ISE<\/em><\/p>\n<p>There is the big problem though. The ISE is completely faking it. Anything inside square brackets is colored as a type.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image6.png\" width=\"370\" height=\"234\"> <\/p>\n<p><em>ISE colors anything inside a square bracket as type<\/em><\/p>\n<p>What\u2019s even worse than that, anything typed is colored as if it was a command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image7.png\" width=\"492\" height=\"85\"><\/p>\n<p><em>non-existing cmdlets colored nonetheless<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>If you look at the same stretch of code in PrimalScript 2012 you see that the non-existing types and cmdlets are simply not colored.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2013\/02\/image8.png\" width=\"479\" height=\"359\"> <\/p>\n<p>Now, mind you, in the real world that can mean that these types and cmdlets simply don\u2019t exist on the local machine but are perfectly valid on the intended target of that script. PrimalScript provides a mechanism for adding types and cmdlets from remote machines and dynamically switching between them. <\/p>\n<p>That allows you to use syntax coloring the way it was intended to be used; to help you code better and with less errors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Syntax coloring for programming languages was originally introduced as a visual aid to assist developers in assessing the syntactical correctness of code. Unlike the squiggly red or green underlines in Microsoft Word colors indicate validation rather than error. So while glancing at a syntax colored stretch of code the usual green hue of comments and [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[17,410,21,25],"tags":[401,99,150,449,28,37,557,799,756],"class_list":["post-5666","post","type-post","status-publish","format-standard","hentry","category-20000-feet","category-primalscript-software-news","category-software-news","category-windows-powershell","tag-net","tag-c","tag-cmdlet","tag-ise","tag-powershell","tag-primalscript","tag-syntax-coloring","tag-types","tag-v3"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=5666"}],"version-history":[{"count":4,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5666\/revisions"}],"predecessor-version":[{"id":5672,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/5666\/revisions\/5672"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=5666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=5666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=5666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}