{"id":4085,"date":"2025-11-21T17:09:07","date_gmt":"2025-11-21T15:09:07","guid":{"rendered":"https:\/\/elnostreraco.com\/blog\/?p=4085"},"modified":"2025-11-21T17:09:07","modified_gmt":"2025-11-21T15:09:07","slug":"english-tip-for-quick-bug-finding-follow-the-line-of-sight","status":"publish","type":"post","link":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/","title":{"rendered":"[English] Tip for quick bug finding: Follow the line of sight"},"content":{"rendered":"\n<p>What can we do to find bugs quickly?<br><br>To fix bugs we need to quickly undestand the logic flow of the code. Having deeply nested if-else statements hurt code glanceability. We could improve code glanceability.<br><br>What I mean with glanceability? Let&#8217;s see an example.<br><br>Can you see where is the \u201chappy path\u201d and where are the \u201cerror paths\u201d only by glancing at this blocks of characters without knowing the real code?<br><br>\n<code><pre>\nprocess <- function(authorization_header, bearer_token) {\n  status <- \"\"\n\n  if (authorization_header != \"\") {\n    if (length(bearer_token) != 2) {\n      status <- \"ok\"\n    } else {\n      status <- \"invalid bearer token format\"\n    }\n  } else {\n    status <- \"missing authorization header\"\n  }\n\n  return(status)\n}<\/pre><\/code>\n<br><br>Having nested happy paths increases the cognitive load. We have to actually read the code in order to understand the happy and error paths.<br><br>Moving nested ifs to \u201cGuard statements\u201d without \"else\" statements translates to less cognitive effort undestanding the code, because having left-aligned happy path make each code \u201chappy path\u201d and \u201cerror paths\u201d obvious.<br><br>Ok. Try again.<br><br>Can you see where is the \u201chappy path\u201d and where are the \u201cerror paths\u201d only by glancing at this blocks of characters without knowing the real code?<br><br>\n<code><pre>process <- function(authorization_header, bearer_token) {\n  if (is.null(authorization_header) || authorization_header == \"\") {\n    return(\"missing authorization header\")\n  }\n\n  if (length(bearer_token) != 2) {\n    return(\"invalid bearer token format\")\n  }\n\n  \"ok\"\n}\n<\/pre><\/code>\n<br><br>The vertical line at the minimum indentation level represents the \"core logic\".<br>Any vertical line with more indentation represents anything out of the ordinary: error handling and guards.<br><br>And since our eyes are very good at following lines, the line of sight (the vertical line at the minimum indentation level) guides us and greatly improves the experience of glancing at a piece of code.<br><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What can we do to find bugs quickly? To fix bugs we need to quickly undestand the logic flow of the code. Having deeply nested if-else statements hurt code glanceability. We could improve code glanceability. &hellip; <\/p>\n","protected":false},"author":1,"featured_media":4087,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4085","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[English] Tip for quick bug finding: Follow the line of sight ~ General<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\" \/>\n<meta property=\"og:locale\" content=\"ca_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[English] Tip for quick bug finding: Follow the line of sight ~ General\" \/>\n<meta property=\"og:description\" content=\"What can we do to find bugs quickly? To fix bugs we need to quickly undestand the logic flow of the code. Having deeply nested if-else statements hurt code glanceability. We could improve code glanceability. &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\" \/>\n<meta property=\"og:site_name\" content=\"Jordi Rosell\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/jrosell\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-21T15:09:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1161\" \/>\n\t<meta property=\"og:image:height\" content=\"732\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"jrosell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jrosell\" \/>\n<meta name=\"twitter:site\" content=\"@jrosell\" \/>\n<meta name=\"twitter:label1\" content=\"Escrit per\" \/>\n\t<meta name=\"twitter:data1\" content=\"jrosell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Temps estimat de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuts\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\"},\"author\":{\"name\":\"jrosell\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/af160702c4f0ec816120b9fa60f5f8d4\"},\"headline\":\"[English] Tip for quick bug finding: Follow the line of sight\",\"datePublished\":\"2025-11-21T15:09:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\"},\"wordCount\":231,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg\",\"articleSection\":[\"General\"],\"inLanguage\":\"ca\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\",\"url\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\",\"name\":\"[English] Tip for quick bug finding: Follow the line of sight ~ General\",\"isPartOf\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg\",\"datePublished\":\"2025-11-21T15:09:07+00:00\",\"author\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/af160702c4f0ec816120b9fa60f5f8d4\"},\"breadcrumb\":{\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#breadcrumb\"},\"inLanguage\":\"ca\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ca\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage\",\"url\":\"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg\",\"contentUrl\":\"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg\",\"width\":1161,\"height\":732,\"caption\":\"Guilherme Tavares's code bug photo, licensed as CC BY 2.0\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Inici\",\"item\":\"https:\/\/elnostreraco.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"General\",\"item\":\"https:\/\/elnostreraco.com\/blog\/category\/general\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"[English] Tip for quick bug finding: Follow the line of sight\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/#website\",\"url\":\"https:\/\/elnostreraco.com\/blog\/\",\"name\":\"Jordi Rosell\",\"description\":\"Conversi\u00f3, eCommerce i Marketing online\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/elnostreraco.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ca\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/af160702c4f0ec816120b9fa60f5f8d4\",\"name\":\"jrosell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ca\",\"@id\":\"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8e2c92ba58be3b381bdc53ea33374b70e1091d8288204187f0645d151e112925?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8e2c92ba58be3b381bdc53ea33374b70e1091d8288204187f0645d151e112925?s=96&d=mm&r=g\",\"caption\":\"jrosell\"},\"description\":\"Consultor, professor i conferenciant. Ajudo als meus clients en la definici\u00f3 estrat\u00e8gica, l'an\u00e0lisi de dades, la presa de decisions i la millora de resultats.\",\"sameAs\":[\"http:\/\/elnosstreraco.com\/blog\",\"http:\/\/www.facebook.com\/jrosell\",\"https:\/\/x.com\/jrosell\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[English] Tip for quick bug finding: Follow the line of sight ~ General","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/","og_locale":"ca_ES","og_type":"article","og_title":"[English] Tip for quick bug finding: Follow the line of sight ~ General","og_description":"What can we do to find bugs quickly? To fix bugs we need to quickly undestand the logic flow of the code. Having deeply nested if-else statements hurt code glanceability. We could improve code glanceability. &hellip;","og_url":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/","og_site_name":"Jordi Rosell","article_author":"http:\/\/www.facebook.com\/jrosell","article_published_time":"2025-11-21T15:09:07+00:00","og_image":[{"width":1161,"height":732,"url":"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg","type":"image\/jpeg"}],"author":"jrosell","twitter_card":"summary_large_image","twitter_creator":"@jrosell","twitter_site":"@jrosell","twitter_misc":{"Escrit per":"jrosell","Temps estimat de lectura":"2 minuts"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#article","isPartOf":{"@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/"},"author":{"name":"jrosell","@id":"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/af160702c4f0ec816120b9fa60f5f8d4"},"headline":"[English] Tip for quick bug finding: Follow the line of sight","datePublished":"2025-11-21T15:09:07+00:00","mainEntityOfPage":{"@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/"},"wordCount":231,"commentCount":0,"image":{"@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage"},"thumbnailUrl":"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg","articleSection":["General"],"inLanguage":"ca","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/","url":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/","name":"[English] Tip for quick bug finding: Follow the line of sight ~ General","isPartOf":{"@id":"https:\/\/elnostreraco.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage"},"image":{"@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage"},"thumbnailUrl":"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg","datePublished":"2025-11-21T15:09:07+00:00","author":{"@id":"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/af160702c4f0ec816120b9fa60f5f8d4"},"breadcrumb":{"@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#breadcrumb"},"inLanguage":"ca","potentialAction":[{"@type":"ReadAction","target":["https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/"]}]},{"@type":"ImageObject","inLanguage":"ca","@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#primaryimage","url":"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg","contentUrl":"https:\/\/elnostreraco.com\/blog\/wp-content\/uploads\/1703252007_e0c4abef81_o.jpg","width":1161,"height":732,"caption":"Guilherme Tavares's code bug photo, licensed as CC BY 2.0"},{"@type":"BreadcrumbList","@id":"https:\/\/elnostreraco.com\/blog\/english-tip-for-quick-bug-finding-follow-the-line-of-sight\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Inici","item":"https:\/\/elnostreraco.com\/blog\/"},{"@type":"ListItem","position":2,"name":"General","item":"https:\/\/elnostreraco.com\/blog\/category\/general\/"},{"@type":"ListItem","position":3,"name":"[English] Tip for quick bug finding: Follow the line of sight"}]},{"@type":"WebSite","@id":"https:\/\/elnostreraco.com\/blog\/#website","url":"https:\/\/elnostreraco.com\/blog\/","name":"Jordi Rosell","description":"Conversi\u00f3, eCommerce i Marketing online","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/elnostreraco.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ca"},{"@type":"Person","@id":"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/af160702c4f0ec816120b9fa60f5f8d4","name":"jrosell","image":{"@type":"ImageObject","inLanguage":"ca","@id":"https:\/\/elnostreraco.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8e2c92ba58be3b381bdc53ea33374b70e1091d8288204187f0645d151e112925?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e2c92ba58be3b381bdc53ea33374b70e1091d8288204187f0645d151e112925?s=96&d=mm&r=g","caption":"jrosell"},"description":"Consultor, professor i conferenciant. Ajudo als meus clients en la definici\u00f3 estrat\u00e8gica, l'an\u00e0lisi de dades, la presa de decisions i la millora de resultats.","sameAs":["http:\/\/elnosstreraco.com\/blog","http:\/\/www.facebook.com\/jrosell","https:\/\/x.com\/jrosell"]}]}},"_links":{"self":[{"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/posts\/4085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/comments?post=4085"}],"version-history":[{"count":7,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/posts\/4085\/revisions"}],"predecessor-version":[{"id":4093,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/posts\/4085\/revisions\/4093"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/media\/4087"}],"wp:attachment":[{"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/media?parent=4085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/categories?post=4085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elnostreraco.com\/blog\/wp-json\/wp\/v2\/tags?post=4085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}