{"id":42,"date":"2012-10-08T08:17:55","date_gmt":"2012-10-08T06:17:55","guid":{"rendered":"http:\/\/blog.kassebaum.eu\/?p=42"},"modified":"2012-10-09T09:20:41","modified_gmt":"2012-10-09T07:20:41","slug":"naming-of-constants","status":"publish","type":"post","link":"https:\/\/www.kassebaum.eu\/blog\/2012\/10\/08\/naming-of-constants\/","title":{"rendered":"Naming of Constants"},"content":{"rendered":"<p>Normally constants improve the readability and maintainability of your code. One example is the minimum value of a single. You can find it in the unit System.Math:<\/p>\n<pre class=\"lang:delphi decode:true\">...\r\nconst\r\n  MinSingle   =  1.4012984643248170709e-45;\r\n...<\/pre>\n<p>Instead of writing the float value it is easier and more readable to use the MinSingle constant.<br \/>\nBut today I found a way how to do this in a very bad way. Someone had to parse a text file. One feature was that is was possible to delete values. Therefore the writer of the file used a special value, a &#8220;*&#8221;. That&#8217;s why I found the following code:<\/p>\n<pre class=\"lang:delphi decode:true\">const\r\n  cStar = '*';\r\nvar\r\n  sValue: string;\r\n  ...\r\nbegin\r\n  ...\r\n  if sValue = cStar then\r\n    DoDeleteValue\r\n  ...\r\nend;<\/pre>\n<p>This is complete nonsense! If you really have no idea how to name your constant then simply don&#8217;t use it! The name always should refer to the meaning of the constant and not to the content.<br \/>\nMaybe something like this is better:<\/p>\n<pre class=\"lang:delphi decode:true\">const\r\n  cDeleteValue = '*';\r\nvar\r\n  sValue: string;\r\n  ...\r\nbegin\r\n  ...\r\n  if sValue = cDeleteValue then\r\n    DoDeleteValue\r\n  ...\r\nend;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Normally constants improve the readability and maintainability of your code. One example is the minimum value of a single. You can find it in the unit System.Math: &#8230; const MinSingle = 1.4012984643248170709e-45; &#8230; Instead of writing the float value it &hellip; <a href=\"https:\/\/www.kassebaum.eu\/blog\/2012\/10\/08\/naming-of-constants\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-tipsandtricks","tag-delphi"],"_links":{"self":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":7,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/42\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}