<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex Winder</title>
    <description>The latest articles on DEV Community by Alex Winder (@alexwinder).</description>
    <link>https://dev.to/alexwinder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F831262%2F4b705cf5-180a-4cc0-9f1f-746d303944bb.jpeg</url>
      <title>DEV Community: Alex Winder</title>
      <link>https://dev.to/alexwinder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexwinder"/>
    <language>en</language>
    <item>
      <title>HTTP Status Codes</title>
      <dc:creator>Alex Winder</dc:creator>
      <pubDate>Sun, 05 Jun 2022 10:46:48 +0000</pubDate>
      <link>https://dev.to/alexwinder/http-status-codes-2fol</link>
      <guid>https://dev.to/alexwinder/http-status-codes-2fol</guid>
      <description>&lt;p&gt;HTTP status codes are a fundamental part of the modern Internet. Whether you are consuming APIs or requesting remote resources, you will be making use of HTTP status codes.&lt;/p&gt;

&lt;p&gt;As a developer these status codes can tell you a lot and help you to identify issues in your application, and also to be able to handle better error messages for your users. &lt;/p&gt;

&lt;p&gt;You may already be aware of some of these, probably the most famous is the &lt;strong&gt;404 Not Found&lt;/strong&gt;. But did you know that these codes have very precise categories? &lt;/p&gt;

&lt;h1&gt;
  
  
  HTTP Status Code Categories
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1xx - Informational Response
&lt;/h2&gt;

&lt;p&gt;Any status code which begins with a &lt;strong&gt;1&lt;/strong&gt; is an informational response and are typically issued while the request continues processing.&lt;/p&gt;

&lt;p&gt;Some informational response codes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;100 Continue&lt;/strong&gt; indicates that everything so far is OK and that the client should continue with the request, or ignore it if it has already finished.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;101 Switching Protocols&lt;/strong&gt; indicates a protocol to which the server switches. With a &lt;strong&gt;101&lt;/strong&gt; response the protocol to which the server switches is specified in the &lt;strong&gt;Upgrade&lt;/strong&gt; header which is also sent from the client. One example of a &lt;strong&gt;101 Switching Protocols&lt;/strong&gt; status code would be when you make a connection to a WebSocket server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2xx - Successful
&lt;/h2&gt;

&lt;p&gt;Any status code which begins with a &lt;strong&gt;2&lt;/strong&gt; is an indication that the requested action from the client was received by the server, it was understood and accepted.&lt;/p&gt;

&lt;p&gt;Generally the most common successful status code is a &lt;strong&gt;200 OK&lt;/strong&gt;. A 200 is the standard response for successful HTTP requests. &lt;/p&gt;

&lt;p&gt;Some successful HTTP status codes which you may see include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;200 OK&lt;/strong&gt; indicates that the request was received and understood by the server and accepted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;202 Accepted&lt;/strong&gt; indicates that the request made has been accepted for processing, but this processing has not yet completed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;204 No Content&lt;/strong&gt; indicates that the server was able to successfully process the request, but there is no content to return to the client.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3xx - Redirection
&lt;/h2&gt;

&lt;p&gt;When a status code begins with a &lt;strong&gt;3&lt;/strong&gt; this means that it is redirection. This indicates that the client must take additional action in order to complete the request.&lt;/p&gt;

&lt;p&gt;Some of the most common HTTP redirection status codes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;301 Moved Permanently&lt;/strong&gt; indicates that the initial and all future requested should be directed to a given URI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;302 Found (Moved Temporarily)&lt;/strong&gt; indicates that the client should look at a URL. The difference between this and 301 is 302 suggests that the requested resource will only temporarily be available from the new URL, but 301 suggests it is permanent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are involved in SEO then you will typically be making use of HTTP 301 and 302 status codes on your servers quite often.&lt;/p&gt;

&lt;h2&gt;
  
  
  4xx - Client Error
&lt;/h2&gt;

&lt;p&gt;Any HTTP status code which begins with a &lt;strong&gt;4&lt;/strong&gt; is an indicator that an error has been caused by the client. &lt;/p&gt;

&lt;p&gt;Some of the most common HTTP client error status codes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;401 Unauthorized&lt;/strong&gt; indicates that authentication is required but has failed or has not yet been provided.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;403 Forbidden&lt;/strong&gt; indicates that the request was valid and was understood but the server is refusing action. This is similar to a 401 Unauthorized, however a 403 might be where a user has authenticated but is attempting to request a resource which they don't have permission to access, whereas a 401 is where the user hasn't authenticated at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;404 Not Found&lt;/strong&gt; is quite possibly the most famous HTTP status code of them all and it indicates that the requested resource could not be found on the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc2324#section-2.3.2" rel="noopener noreferrer"&gt;418 I'm a teapot&lt;/a&gt;&lt;/strong&gt; is a status code which is returned by teapots which have been requested to brew coffee.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5xx - Server Error
&lt;/h2&gt;

&lt;p&gt;When a HTTP status code begins with a &lt;strong&gt;5&lt;/strong&gt; this indicates that there was a problem with the server and so it was unable to fulfil the request.&lt;/p&gt;

&lt;p&gt;Some server error HTTP status codes which you may see include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;500 Internal Server Error&lt;/strong&gt; is a generic error message which is often returned when the server is not configured to handle the response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;503 Service Unavailable&lt;/strong&gt; is when the server cannot handle the request, often because it is overloaded or is down for maintenance. A 503 status is typically a temporary state.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  How can I view HTTP status codes?
&lt;/h1&gt;

&lt;p&gt;As status codes are a fundamental part of browsing any website, the simplest way to view them would be to open up the Network Monitor on your browser whilst viewing the website. This will show you the state of the requested resources as you load different parts of a website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Firefox
&lt;/h2&gt;

&lt;p&gt;To view the Network Monitor on Firefox press &lt;em&gt;Ctrl&lt;/em&gt; + &lt;em&gt;Shift&lt;/em&gt; + &lt;em&gt;E&lt;/em&gt;. This will open a window on your page with the "Network" tab highlighted. Then if you refresh your page you will see all of the resources which are requested with that page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrlj384xjcwpo0dq1r8b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frrlj384xjcwpo0dq1r8b.png" alt="Network Monitor in Firefox"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Chrome
&lt;/h2&gt;

&lt;p&gt;To view the Network Monitor on Chrome press &lt;em&gt;Ctrl&lt;/em&gt; + &lt;em&gt;Shift&lt;/em&gt; + &lt;em&gt;J&lt;/em&gt;. This will open the console window. Then select the "Network" tab. Then refresh your page and you will see all of the resources which are requested with that page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffa2ywrx8p84bojdl9cuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffa2ywrx8p84bojdl9cuh.png" alt="Network Monitor in Chrome"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>So, you have a new website...</title>
      <dc:creator>Alex Winder</dc:creator>
      <pubDate>Sun, 22 May 2022 14:39:26 +0000</pubDate>
      <link>https://dev.to/alexwinder/so-you-have-a-new-website-4m30</link>
      <guid>https://dev.to/alexwinder/so-you-have-a-new-website-4m30</guid>
      <description>&lt;p&gt;You've just finished building your shiny new website and you're ready to release it to the world. You upload it to your webhost or perhaps you change the visibility to public. You then wait for Google to crawl it, or perhaps you submit it to the Google Search Console. However, your website doesn't show in the top result, or even in the first few pages on Google.&lt;/p&gt;

&lt;p&gt;You do some research and find that you need to look into something called SEO. There are tools online which show you things you need to improve on, but the reality is the majority of these tools are just making a best guess as search engines don't publish the metrics they use for indexing their results.&lt;/p&gt;

&lt;p&gt;You set out to do some Search Engine Optimisations to your site. This shouldn't take long.&lt;/p&gt;

&lt;p&gt;You start with making sure that your site is responsive between devices, making sure things are laid out nicely on mobile, tablet, desktops and everything else inbetween.&lt;/p&gt;

&lt;p&gt;Afterwards you make sure that all of your assets are compressed, minified and reduced to their smallest possible size to reduce your page load time and how long it takes for your site to become interactive. You install a caching service or CDN to reduce the amount of time spent downloading files from your site.&lt;/p&gt;

&lt;p&gt;You then find out that the colour scheme and your choice of page elements are not quite as accessible that they could be, so you spend time tweaking colours to not only match your brand but also to improve on the user experience for those with accessibility difficulties. You resize all of the buttons, headings, paragraphs, images, menus, and everything else to give the best possible accessibility to your users. Whilst you're doing this you remember reading about HTML semantics and so you make sure that the format of your website is built so that screen readers can properly parse the structure.&lt;/p&gt;

&lt;p&gt;Your SEO report is getting better at this point and you are rising up the search results, but for results which you didn't ever intend to. So you head back into your content and rewrite pages to target specific keywords, give all of your images the correct descriptions and change headings to better describe the content. You set up some more descriptive URLs but you make sure not to forget to set up 301 redirects from the old URL. You check that your sitemap is correct so that search engines aren't storing incorrect or old data.&lt;/p&gt;

&lt;p&gt;After all this you then need to begin writing blog posts to improve on the reach of your site and to show up for more search terms.&lt;/p&gt;

&lt;p&gt;At this point you're feeling pretty smug with yourself and your website is finally on the first page, or if you're lucky then you're result number 1 for your search terms. But to your horror after a few weeks Google announces some core changes to their algorithm which appears to completely wipes you off the results page, and so you find yourself tweaking your site more in the hope that it improves your ranking.&lt;/p&gt;

&lt;p&gt;The reality is that SEO is a dark art, and website results rankings are dependent on search engines who rarely (if ever) give any indication as to the metrics they use to rank websites. There are SEO "specialists" which claim to be able to guarantee result number 1, but these are often charlatans or will give you results which you never asked for. There are best practices to improve your chances, but only those who have deep understanding of the Google algorithm can guarantee a result.&lt;/p&gt;

&lt;p&gt;Here are a few online tools which can aid with your own SEO improvements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pagespeed.web.dev/"&gt;PageSpeed Insights&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tools.pingdom.com/"&gt;Pingdom Website Speed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gtmetrix.com/"&gt;GTmetrix&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://seositecheckup.com/"&gt;SEO Site Checkup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The above links are not a guaranteed way to improve your site, but do aid with some basic best practices.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>watercooler</category>
      <category>design</category>
      <category>webdev</category>
      <category>seo</category>
    </item>
    <item>
      <title>Complicated code is not clever</title>
      <dc:creator>Alex Winder</dc:creator>
      <pubDate>Wed, 16 Mar 2022 20:00:01 +0000</pubDate>
      <link>https://dev.to/alexwinder/complicated-code-is-not-clever-373h</link>
      <guid>https://dev.to/alexwinder/complicated-code-is-not-clever-373h</guid>
      <description>&lt;p&gt;I remember when I first started learning to code, I would be reading snippets online would find myself having to read things over and over again to be able to understand them. &lt;/p&gt;

&lt;p&gt;The problem wasn't with the logic of the code or with what it was doing, it was how it was written.&lt;/p&gt;

&lt;p&gt;Consider the below PHP code snippets, which do you think is more readable?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;();};&lt;/span&gt;

&lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'t'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="s1"&gt;'un'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nv"&gt;$ufn&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$uln&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'tn'&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;utn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ui&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;outputArrayAsJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$array&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'time'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="s1"&gt;'userName'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'teamName'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getUserTeamName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nf"&gt;outputArrayAsJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is obviously subjective, but I think generally more people (developer and not) would be able to understand the latter solution over the former.&lt;/p&gt;

&lt;p&gt;Using the above examples which are written in PHP just scanning over the code of each you can quickly understand what is happening in the second snippet much faster than the first. &lt;/p&gt;

&lt;p&gt;You're unlikely to need to go searching through your codebase to find what &lt;code&gt;getUserTeamName($user-&amp;gt;id)&lt;/code&gt; does, its name and arguments are already indicative of its use case. However compare this with &lt;code&gt;utn($ui)&lt;/code&gt; which is not so clear. I can guarantee that if you left this codebase for any period of time you would need to go back to the &lt;code&gt;utn&lt;/code&gt; function to remind yourself what it does.&lt;/p&gt;

&lt;p&gt;There are going to be things referenced in any language which are outside of our control, such as bundled standard libraries, but the things which we do have control over should be produced to as high a standard as possible.&lt;/p&gt;

&lt;p&gt;I believe that code should generally read like a story or a book. If you had to constantly keep flicking between random pages of a story would you be likely to finish the book? Almost certainly not. As developers it's important to not only write efficient, but also, understandable code. Doing so reduces technical debt and makes the development experience far more enjoyable.&lt;/p&gt;

&lt;h2&gt;
  
  
  You don't need to be an expert to write clever code.
&lt;/h2&gt;

&lt;p&gt;Here are my top tips for writing clever code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conventions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pick one and stick to it. There is no right or wrong, tabs or spaces, camel-case or snake-case, it doesn't matter - just create a convention stick with it. Consistency is the key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whitespace&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Bunching up concatenations or blocks makes them harder to read. Similarly keeping short statements on one line, and splitting longer statements into multiple lines makes them easier to follow without needing to scroll.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// These are bad&lt;/span&gt;
&lt;span class="nv"&gt;$variable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$variable&lt;/span&gt;&lt;span class="o"&gt;===&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nf"&gt;functionWithLotsOfParameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="nv"&gt;$ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;MyObject&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// These are good&lt;/span&gt;
&lt;span class="nv"&gt;$variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$variable&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;functionWithLotsOfParameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="mi"&gt;5&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="nv"&gt;$ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;MyObject&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Descriptive Names&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make your code the comment. All names which you have control over as a developer should be descriptive. A function called &lt;code&gt;outputArrayAsJson(array $array)&lt;/code&gt; tells the developer exactly what it does without even needing to read the logic inside the function. You are never going to remember exactly what your code does when you revisit it in a year, so make the code readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Comments should explain why you needed to do something, but not how. Code changes often, but comments are commonly missed when the logic changes. I've lost count the number of times where I've copy/pasted code between 2 files and forgotten to update the comment context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scopes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make use of scopes where possible and try to group common logic together. Grouping portions of similar code together, such as in a class, makes things much more maintainable and avoids code repetition. Only use global scopes as an absolute last resort.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This is OK&lt;/span&gt;
&lt;span class="nb"&gt;http_response_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Page not found'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// This is better&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="no"&gt;HTTP_NOT_FOUND&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="no"&gt;HTTP_NOT_FOUND_MESSAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Page not found'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nb"&gt;http_response_code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;HTTP_NOT_FOUND&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;HTTP_NOT_FOUND_MESSAGE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>tips</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
