{"id":2743,"date":"2020-11-09T09:53:46","date_gmt":"2020-11-09T08:53:46","guid":{"rendered":"https:\/\/www.wbscodingschool.com\/?p=2743"},"modified":"2020-11-09T09:53:46","modified_gmt":"2020-11-09T08:53:46","slug":"how-to-write-faster-code","status":"publish","type":"post","link":"https:\/\/www.wbscodingschool.com\/blog\/how-to-write-faster-code\/","title":{"rendered":"How To Write Faster Code: The Complete Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If any of us lived forever, we could always write code refined to perfection. Unfortunately the constraints of time and mortality \u2013 and, less metaphysically, those of our employers \u2013 mean that those of us wishing to learn how to code must also learn how to code relatively quickly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Coding <em>fast<\/em> is a wholly other skill than coding <em>well<\/em>. In fact, it is arguably less a skill in its own right than the aggregate of an entire constellation of apparently minor skills. It is important and complex enough a topic that we intend to split this article into two parts, so that we may cover faster coding both in practice and in theory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our article will be organized as follows:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PRACTICAL TIPS<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part0\">Know your editor<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part1\">Do copy, don\u2019t paste<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part2\">Unit tests<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part3\">Mnemonics<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part4\">Start with what you know<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">GENERAL THEORY<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part5\">Keep code simple<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part6\">Write code you can recycle<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part7\">Question your managers<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part8\">Don\u2019t just use the language, understand it<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#part9\">Plan by drawing<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s start us off with the <em>practical<\/em> side of coding quicker \u2013 strictly without compromising quality, of course!<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>PRACTICAL TIPS<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part0\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#1. Know your editor<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many programmers only learn the basic functionality of code editors like Visual Studio Code, PhpStorm, or Pycharm, perhaps because they feel that studying them in greater depth would steal time from whatever coding project they\u2019re working on. Don\u2019t fall for that trap! You may think that learning keyboard shortcuts, or how to quickly find and open files, will only gain a second or two for every paragraph of code you write \u2013 but once you\u2019re doing that instinctively, it can shave off up to 10% of the time you spend in front of the monitor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set aside one day and dedicate it entirely to learning and exercising yourself in the more advanced functions of your editor, particularly if you are assigned a project that requires you to switch to a new one. It\u2019s one of the most direct and universally efficient ways to speed up the coding process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part1\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#2. Do copy, don\u2019t paste.<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As most professional developers will tell you, copying code that works is not \u2018cheating\u2019 \u2013 it\u2019s sparing yourself the futility of reinventing the wheel. Thus, we wholeheartedly recommend using Google to look for solutions to programming problems which have been made publicly available, particularly if your aim is to code more quickly. That said, here\u2019s a helpful little trick not many have tried out: don\u2019t paste the above-mentioned solutions into your code, but take the time to manually type them out yourself.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/www.wbscodingschool.com\/files\/AdobeStock-by-fizkes_207455020-1024x682.jpeg\" alt=\"Curious Caucasian male businessman looking at screen of African American colleague busy working at laptop, worker glancing at rival computer, being smart, sly, cunning. Concept of rivalry cooperation\" class=\"wp-image-28784\"\/><figcaption>Adobe Stock \/ fizkes<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You may think this will rather slow you down \u2013 and for the first few weeks, granted, it probably will. But it will also brand the solutions you\u2019re copying into your brain and automate them into your fingertips. Also, and crucially, you will gain a more intimate conceptual understanding of what you\u2019re working with. Eventually you\u2019ll find yourself writing these solutions without copying them from anywhere, possibly without even thinking about them, and you\u2019ll be whooshing through code that would have previously taken multiple stops and starts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part2\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#3. Unit tests<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s actually surprising how many excellent developers have never been taught the value of unit tests. If you\u2019re unfamiliar with the term, these simply consist in testing small or smaller units of code by themselves, as distinct from integrated tests, which run a program (or a large part of a program) in its entirety.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Running regular unit tests doesn\u2019t mean that your code will be free of bugs, but it does mean that you will find them in a fraction of the time it would take you to reexamine your entire code. Resist the illusion of speed you get from blazing through your entire project in one go, particularly if you\u2019re relatively inexperienced. Instead, keep your units of code short and test each of them methodically. It may feel slower while you\u2019re doing it, but in reality you are preemptively sweeping aside what could be hours of work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part3\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#4. Mnemonics<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We all retain and process memories differently, meaning that different learning methods will work best for different people. That said, not many are aware of some of the <a href=\"https:\/\/www.memory-improvement-tips.com\/remembering-lists.html\" target=\"_blank\" rel=\"noopener\">simple tricks<\/a> you <a href=\"https:\/\/artofmemory.com\/wiki\/How_to_Build_a_Memory_Palace\" target=\"_blank\" rel=\"noopener\">can use<\/a> to <a href=\"https:\/\/www.magneticmemorymethod.com\/brain-exercises\/\" target=\"_blank\" rel=\"noopener\">train your memory<\/a> and make sure you retain information for long stretches of time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is important for programmers because methodically committing to memory ways to cut down loops or to more efficiently exploit dataframes is perhaps the most powerful cognitive exercise to become a faster coder, albeit not the easiest to master. Practice mnemonic methods, and then use them whenever you come across a clever few lines of somebody else\u2019s code (you can find a ton on Kaggle, if you\u2019re not sure where to start). Naturally, you should also make sure you are using what you\u2019ve memorized in your own projects, further ingraining it in your mind. This can take some effort to pull off, but done consistently, it\u2019ll likely push you forward and permanently speed you up more than any other tip on this list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part4\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#5. Start with what you know<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You always want to make sure you have a plan before you start a project, but once you do start, go for the easy bits first. Many of us have an instinct to \u2018get the hard bit out of the way\u2019 when working, and while this is helpful in many fields, it can actually be counter-productive in programming.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If there is a part of your project that you already understand very well, start there. Write whatever code is the least troublesome first, especially for the projects that are most complicated and ambitious. The reason we give this advice is that problems in programming are frequently sequential \u2013 solving the first part makes it easier to solve the next, which makes it easier to solve the next, and so on. Naturally, this isn\u2019t just going to magically solve all of the remaining intellectual or creative challenges, but at the very least it should get you thinking in the right direction. And sometimes that can make all the difference in the world.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This was the last of our practical tips on writing faster code. Now let\u2019s look at the general theory and the outlook that will complement these tips!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>GENERAL THEORY<\/strong><\/h1>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/www.wbscodingschool.com\/files\/iStock-1172878142-by-metamorworks-1024x606.jpg\" alt=\"\" class=\"wp-image-2742\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting on the theory of writing faster code, it\u2019s worth emphasizing that the precondition for efficient coding is a healthy, balanced approach to the work of programming in general. You\u2019re not going to code more quickly if you\u2019re not getting enough sleep or managing your workload reasonably, and if that\u2019s the case, you might want to take a look at <a href=\"https:\/\/www.wbscodingschool.com\/blog\/non-coding-laws-of-coding\/\">our article on programming and lifestyle<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have that bit down pat, then great \u2013 let\u2019s dive into our suggestions!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part5\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#1. Keep code simple<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In general, this is one of the golden rules of programming, and for good reason. Among its many advantages, there\u2019s the fact that simple code is less likely to lead to mistakes, and even when it does lead to mistakes, it is so much easier to fix them. Thus, simple code is not just faster to write because it\u2019s shorter, it also saves you a ton of time in the process of debugging and\/or redesigning.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your code is overly complex (and assuming you\u2019re not overly experienced and deliberately trying to outsmart everyone \u2013 not a good idea!), that typically comes down to a.) insufficient familiarity with your programming language of choice and the tools it offers, or b.) a relatively fuzzy understanding of an important concept in coding, like objects or recursion. Identify the area where your knowledge is wobbly and study to fix that. If you need to go back to basics, do it. This is about your core competence as a programmer, and there is no way to write quicker code than to improve that!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part6\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#2. Write code you can recycle<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many of the tasks you\u2019ll be presented with over your career will overlap with each other. You may need to build UI structures for different websites which do more or less the same thing, or games that belong to the same genre. For this reason, you should try to build code that is easy to reuse whenever this is a possibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As an indication \u2013 though by no means an unbreakable rule \u2013 make sure you\u2019re writing code which you will be able to implant into a different project without too much effort, rather than patterns inextricably embedded into the program in its entirety. This will help you cut down the amount of time you dedicate to each problem by having some of its components resolved in advance and ready to be integrated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part7\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#3. Question your managers<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This one becomes essential if you\u2019re working for someone who is not themselves a programmer. Any time you are assigned a project, before you write a single line of code, you should always critically examine the task you are being given: what problem are you being asked to solve, and why do they want you to do it this way in particular?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/www.wbscodingschool.com\/files\/AdobeStock-by-Antonioguillem_132644175-1024x682.jpeg\" alt=\"Boss denying something saying no with a finger gesture to an upset employee in her office\" class=\"wp-image-28781\"\/><figcaption>Adobe Stock \/ Antonioguillem<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As the person who is actually building the code, you are the one who is best placed to see what the optimal solution is and what\u2019s the best way to get there. Take a moment to think about it, see if you can come up with a better way of doing things than what your managers assigned, even at the cost of turning the whole project upside down, and if so, raise the issue. If your superiors are asking you to do something in a way that will take you twice as much time as is necessary, and you simply go along without question, then you have only yourself to blame for the waste of time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part8\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#4. Don\u2019t just use the language, understand it<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Programming may be an intellectual activity, but that doesn\u2019t mean the response to every problem will involve locking yourself in your mind palace. Sometimes you have to look at the material you are working with \u2013 for instance, some variable you did not fully understand, or a symbol you did not take the time to properly investigate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Can you explain what \u2018%\u2019 really means in your programming language, or are you just using it because it sort of seems to work the way it did in another language you\u2019re more familiar with? You may think you can wing it without fully looking into these matters \u2013 and granted, sometimes you can \u2013 but there is hardly a more common cause for simple tasks taking unreasonably long times than a programmer not properly understanding their language.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"part9\"> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>#5. Plan by drawing<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are very many ways to plan a project, and every programmer will have his or her favorite approach. In general, though, putting pen on paper before you put fingers on keyboard, and making a drawing of your project, is something almost everyone finds helpful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Going into a project with a well thought-out plan is key to saving time in implementation. Laying said plan down on paper so that you can see it with your own eyes, rather than attempting to hold six complicated concepts in your mind simultaneously, will let you spot potential problems and breaking points much more easily. You can then work around them in advance, instead of spending hours past your deadline trying to figure out what went wrong. That\u2019s well worth investing a little longer at the drawing board, as it\u2019s a classic case of using time to save time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2026And with that, we have covered both the practice and the theory of writing faster code! If this article was helpful to you, take a look also at <a href=\"https:\/\/www.wbscodingschool.com\/blog\/debugging-guide-how-to\/\">our guide on efficient debugging<\/a> \u2013 and soon you\u2019ll be unstoppable!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to roll out your beautiful code faster? Here are a few practical tricks that will instantly boost your programming speed.<\/p>\n","protected":false},"author":17,"featured_media":2741,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[42],"tags":[],"class_list":["post-2743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/posts\/2743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/comments?post=2743"}],"version-history":[{"count":1,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/posts\/2743\/revisions"}],"predecessor-version":[{"id":62643,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/posts\/2743\/revisions\/62643"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/media\/2741"}],"wp:attachment":[{"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/media?parent=2743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/categories?post=2743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wbscodingschool.com\/de\/wp-json\/wp\/v2\/tags?post=2743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}