{"componentChunkName":"component---node-modules-gatsby-theme-medium-to-own-blog-src-templates-blog-post-js","path":"/i-still-read-too-many-switches/","result":{"data":{"site":{"siteMetadata":{"siteUrl":"https://javame.netlify.app","githubUrl":"https://github.com/aterreno/blog"}},"mdx":{"fields":{"slug":"/i-still-read-too-many-switches/"},"excerpt":"Yes, I still read too much code with switches inside. I hate it. There’s still also a \"nice\" page on the official website of Sun on how to…","timeToRead":1,"frontmatter":{"title":"I still read too many switches","description":"","categories":[],"date":"September 30, 2007","canonical_link":"https://javame.netlify.app//i-still-read-too-many-switches-b32a306ca4ee"},"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"I still read too many switches\",\n  \"description\": \"\",\n  \"date\": \"2007-09-30T00:00:00.000Z\",\n  \"categories\": [],\n  \"published\": true,\n  \"canonical_link\": \"https://javame.netlify.app//i-still-read-too-many-switches-b32a306ca4ee\",\n  \"redirect_from\": [\"/i-still-read-too-many-switches-b32a306ca4ee\"]\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Yes, I still read too much code with switches inside. I hate it. There\\u2019s still also a \\u201Cnice\\u201D page on the official website of Sun on how to write really nasty code, it\\u2019s \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html\",\n    \"target\": \"_blank\",\n    \"rel\": \"nofollow noopener noreferrer\"\n  }), \"here\"), \". I don\\u2019t wanna infect this blog, so I\\u2019m not pasting that example of code here. I paste only a quote, it says:\"), mdx(\"blockquote\", null, mdx(\"p\", {\n    parentName: \"blockquote\"\n  }, \"Deciding whether to use if-then-else statements or a switch statement is sometimes a judgement call.\")), mdx(\"p\", null, \"Yes, indeed. And the judgement call is: \\u201Cshould I write a long list of if then else or maybe think on some kind of polymorphism?\\u201D The switch is not an option. Switch smells of poor design, smells of \\u201Cyou dude, writing that code, you don\\u2019t know what object oriented is!\\u201C. It\\u2019s not well testable, it\\u2019s ugly.\"), mdx(\"p\", null, \"The web is plenty of examples on how to refactor from a switch to a decent design, just searching right now, I\\u2019ve found a good one \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"http://hanuska.blogspot.com/2006/08/swich-statement-code-smell-and.html\",\n    \"target\": \"_blank\",\n    \"rel\": \"nofollow noopener noreferrer\"\n  }), \"here\"), \".\"), mdx(\"p\", null, \"There\\u2019s another one \", mdx(\"a\", _extends({\n    parentName: \"p\"\n  }, {\n    \"href\": \"http://sis36.berkeley.edu/projects/streek/agile/bad-smells-in-code.html#Switch+Statements\",\n    \"target\": \"_blank\",\n    \"rel\": \"nofollow noopener noreferrer\"\n  }), \"here\"), \", with strategies for getting rid of it.\"), mdx(\"p\", null, \"So why are you writing still switches? Let me know, we can talk about this and maybe I can help you to quit.\"), mdx(\"p\", null, \"Switch off the switches. That\\u2019s the tip.\\xA0:-)\"), mdx(\"p\", null, \"Hey, this does not allow you to write a long chain of if then else blocks! Think on polymorphism every time you write an if, ask to your pair what he thinks, maybe you can move that responsibility somewhere else, one if is still fine but when you start to have an else\\u2026 Mhmmm\\u2026.\"), mdx(\"p\", null, \"I really hope that someone is reading and I\\u2019ll read less switch stuff\\u2026\"));\n}\n;\nMDXContent.isMDXComponent = true;"},"allWebMentionEntry":{"nodes":[]}},"pageContext":{"id":"b3beefea-888d-58b5-9676-7689e3c3eee0","previous":{"id":"9ea1553a-72dd-5a20-89e9-6f3057792488","fields":{"slug":"/some-stuff-you-might-try-in-your-retrospectives/","published":true},"frontmatter":{"redirect_from":["/some-stuff-you-might-try-in-your-retrospectives-4462ac2e9ec2"],"redirect_to":null,"title":"Some stuff you might try in your retrospectives"}},"next":{"id":"122907b8-702f-59d7-b463-e7afea379737","fields":{"slug":"/javaday-in-turin/","published":true},"frontmatter":{"redirect_from":["/javaday-in-turin-a9e9d310568f"],"redirect_to":null,"title":"Javaday in Turin"}},"permalink":"https://javame.netlify.app/i-still-read-too-many-switches/","themeOptions":{"plugins":[],"config":{"title":"Antonio Terreno","description":"Antonio Terreno's blog archive","shortBio":"","bio":"Principal Consultant at Equal Experts","author":"Antonio Terreno","githubUrl":"https://github.com/aterreno/blog","siteUrl":"https://javame.netlify.app/","social":{"twitter":"javame","medium":"","facebook":"","github":"aterreno","linkedin":"antonioterreno","instagram":"tritonitri"},"goatCounterCode":null}}}},"staticQueryHashes":["4131332129","645483741"]}