{"id":100,"date":"2025-08-30T04:33:07","date_gmt":"2025-08-30T04:33:07","guid":{"rendered":"http:\/\/katzcs.com\/?page_id=100"},"modified":"2025-08-30T04:53:29","modified_gmt":"2025-08-30T04:53:29","slug":"readability-variables-how-to-name-them","status":"publish","type":"page","link":"http:\/\/katzcs.com\/?page_id=100","title":{"rendered":"Readability &#8211; Variables &#8211; How to name them"},"content":{"rendered":"\n<div style=\"height:13px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h1 class=\"wp-block-heading has-text-align-center\">Readability Expectations<\/h1>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\">Variables &amp;&amp; How to Name Them<\/h2>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group has-tertiary-background-color has-background has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\" style=\"margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50)\">\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-1a9727ad wp-block-columns-is-layout-flex\" style=\"margin-top:0;margin-bottom:0\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<p>A general rule: <em><strong>You should always name your variable something logical &#8212; something that is meaningful within a specific section of code.<\/strong><\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"advice-java\">Variable Naming Advice:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Avoid spelling errors.<\/strong> While this can be tricky since you can&#8217;t spell check it does actually make a difference.\n<ul class=\"wp-block-list\">\n<li>Consider a program with multiple coders and you make a function called euqals instead of equals<\/li>\n\n\n\n<li>If the spelling is bad enough you may be violating the &#8220;meaningful name&#8221; rule!<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Don&#8217;t abuse case sensitivity.\n<ul class=\"wp-block-list\">\n<li>Don&#8217;t create two variables that only differ in capitalization (i.e. &#8216;one&#8217; and &#8216;One&#8217;). This will get confusing.<\/li>\n\n\n\n<li>Don&#8217;t create a variable that is a capitalized reserved word.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Avoid your own abbreviations\n<ul class=\"wp-block-list\">\n<li>While you may come up with shorthand that makes sense at the moment it may be something you easily forget\n<ul class=\"wp-block-list\">\n<li>If you really want to do this&#8230; add a comment explaining what the abbreviation means<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>If someone else is looking at your program this doesn&#8217;t follow the &#8220;meaningful name&#8221; rule<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Avoid swearing\n<ul class=\"wp-block-list\">\n<li>It may seem funny or maybe you are venting frustration when debugging\u2026 but it is easy to forget you have inappropriate things in your code.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"957\" height=\"1024\" src=\"http:\/\/katzcs.com\/wp-content\/uploads\/2025\/08\/variable_name_tweet-957x1024.jpeg\" alt=\"\" class=\"wp-image-101\" style=\"width:331px;height:auto\" srcset=\"http:\/\/katzcs.com\/wp-content\/uploads\/2025\/08\/variable_name_tweet-957x1024.jpeg 957w, http:\/\/katzcs.com\/wp-content\/uploads\/2025\/08\/variable_name_tweet-280x300.jpeg 280w, http:\/\/katzcs.com\/wp-content\/uploads\/2025\/08\/variable_name_tweet-768x822.jpeg 768w, http:\/\/katzcs.com\/wp-content\/uploads\/2025\/08\/variable_name_tweet.jpeg 1170w\" sizes=\"auto, (max-width: 957px) 100vw, 957px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-702decc0 wp-block-columns-is-layout-flex\" style=\"margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--50)\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<h2 class=\"wp-block-heading\" style=\"font-size:clamp(25.014px, 1.563rem + ((1vw - 3.2px) * 1.733), 42px);font-style:normal;font-weight:700;line-height:1.2\">Only exception:<\/h2>\n\n\n\n<p>In my opinion the one exception to the &#8220;meaningful name&#8221; rule is loop counter variables!<\/p>\n\n\n\n<p>If you are writing a <em>simple<\/em> loop and all your variable does is count, then its acceptable to use i, j, x, temp, etc.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:clamp(25.014px, 1.563rem + ((1vw - 3.2px) * 1.733), 42px);font-style:normal;font-weight:700;line-height:1.2\">Common syntax naming rules:<\/h2>\n\n\n\n<p>These rules apply to many languages including java and C++:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A variable cannot contain whitespace.<\/li>\n\n\n\n<li>You cannot use a reserved word as a variable name (i.e. public, float).<\/li>\n\n\n\n<li>You cannot start a variable with a number.<\/li>\n\n\n\n<li>Many languages restrict the use of special characters in variable names<\/li>\n<\/ul>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n<\/div>\n\n\n\n<p>Be aware: These are my opinions. Other instructors will have their own policies! <\/p>\n\n\n<div class=\"wp-block-post-date__modified-date wp-block-post-date\"><time datetime=\"2025-08-30T04:53:29+00:00\">August 30, 2025<\/time><\/div>\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-container-core-group-is-layout-b2082ebc wp-block-group-is-layout-constrained\" style=\"margin-top:0;margin-bottom:0;padding-top:100px;padding-right:20px;padding-bottom:100px;padding-left:20px\">\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-9cad5244 wp-block-columns-is-layout-flex\" style=\"margin-top:0;margin-bottom:0\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<p>Check out more of my readability expectations by language:<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-buttons is-content-justification-space-between is-layout-flex wp-container-core-buttons-is-layout-8f3c3dcc wp-block-buttons-is-layout-flex\" style=\"margin-top:40px\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-primary-background-color has-background wp-element-button\" style=\"border-radius:0px\">C++<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-primary-background-color has-background wp-element-button\" style=\"border-radius:0px\">Java<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-primary-background-color has-background wp-element-button\" style=\"border-radius:0px\">Python<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Readability Expectations Variables &amp;&amp; How to Name Them A general rule: You should always name your variable something logical &#8212; something that is meaningful within a specific section of code. Variable Naming Advice: Only exception: In my opinion the one exception to the &#8220;meaningful name&#8221; rule is loop counter variables! If you are writing a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":82,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-100","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/pages\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/katzcs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":3,"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/pages\/100\/revisions"}],"predecessor-version":[{"id":109,"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/pages\/100\/revisions\/109"}],"up":[{"embeddable":true,"href":"http:\/\/katzcs.com\/index.php?rest_route=\/wp\/v2\/pages\/82"}],"wp:attachment":[{"href":"http:\/\/katzcs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}