<?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: PHP and cigars</title>
    <description>The latest articles on DEV Community by PHP and cigars (@phpandcigars).</description>
    <link>https://dev.to/phpandcigars</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%2F16739%2Fdf96ec2b-20af-4510-9554-a281994f24b7.jpg</url>
      <title>DEV Community: PHP and cigars</title>
      <link>https://dev.to/phpandcigars</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/phpandcigars"/>
    <language>en</language>
    <item>
      <title>Ergonomics of desk-setups</title>
      <dc:creator>PHP and cigars</dc:creator>
      <pubDate>Thu, 09 Apr 2020 16:11:38 +0000</pubDate>
      <link>https://dev.to/phpandcigars/ergonomics-of-desk-setups-5d53</link>
      <guid>https://dev.to/phpandcigars/ergonomics-of-desk-setups-5d53</guid>
      <description>&lt;p&gt;Hi everybody,&lt;/p&gt;

&lt;p&gt;I wondered, how many of you are aware of ergonomic rules on how to create an ergonomic workspace. Specially in the homeoffice. When you browse for example the hashtag desksetup on instagram you will find that most desks are placed against a wall, so you can place rgb strip or a picture frame and simply make a good picture.&lt;/p&gt;

&lt;p&gt;But that is actually quite bad for your eyes, if you can't focus on a different distance for the whole day. I tend to put my desks on a right angle from the wall so a can look into the room.&lt;/p&gt;

&lt;p&gt;What are your toughts on that? I would like to see your desk setups, that have an ergonomic purpose.&lt;/p&gt;

&lt;p&gt;Stay home, stay save.&lt;/p&gt;

</description>
      <category>ergonomics</category>
      <category>homeoffice</category>
      <category>workstations</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Is it possible to code without drugs?</title>
      <dc:creator>PHP and cigars</dc:creator>
      <pubDate>Tue, 18 Feb 2020 16:58:00 +0000</pubDate>
      <link>https://dev.to/phpandcigars/is-it-possible-to-code-without-drugs-56ln</link>
      <guid>https://dev.to/phpandcigars/is-it-possible-to-code-without-drugs-56ln</guid>
      <description>&lt;p&gt;I have a question for you all? Is it possible to code totally straight edge? I drink energy drinks to keep my concentration for eight hours a day? Do you even know somebody who is able to code without any drugs? No nicotine, no caffeine, no worse?&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Learn to say no!</title>
      <dc:creator>PHP and cigars</dc:creator>
      <pubDate>Tue, 03 Oct 2017 04:08:20 +0000</pubDate>
      <link>https://dev.to/phpandcigars/learn-to-say-no-6ie</link>
      <guid>https://dev.to/phpandcigars/learn-to-say-no-6ie</guid>
      <description>&lt;p&gt;Sometimes, being a developer, your job consists of just saying no. No to a feature, a client or your boss requested, no to a new project or no to a developer who is applying for a job.&lt;/p&gt;

&lt;p&gt;For me writing code is easy. Sometimes I need to sleep over a problem, but usually I find a solution to a problem quite fast. But dealing with people is a hard thing to do. You have sometimes to do hard decisions.&lt;/p&gt;

&lt;p&gt;I just want to give you some examples, where saying no saved my ass in the last two years and where saying no would have been a better approach.&lt;/p&gt;

&lt;p&gt;Telling a to unexperienced developer that, he is still not ready is hard. Specially, when it's hard to find new people anyway. It took me a lot of time to find another co-worker, now I have someone, who wrote productive code after just after two weeks in the new job.&lt;/p&gt;

&lt;p&gt;My boss asked me to not focus so much on the admin-interface of the online-shop. I refused to do a sloppy job. Now I have something, were I can tell everybody in the company to dispatch the orders with just a two minutes introduction on what they have to do.&lt;/p&gt;

&lt;p&gt;My other boss asked me to change the color-schema of an online-shop to "anthracite". On a screen there is not such color. It would have slowed down the render-times, if I used images. So I refused to do so and customers are satisfied with the look and render-times.&lt;/p&gt;

&lt;p&gt;A thing I did not clearly refused was to do a project with someone for a hourly monetary compensation. I told my boss, that this would just lead to a lot of emails which requests to change a lot of "small things". Always accompanied by the word "just". Here I instantly regretted not to stayed firm in my position to refuse to do this project for a fix price.&lt;/p&gt;

&lt;p&gt;Especially when you are in an environment where you have to deal with non-technical-staff and employers, your role should be more than, "the one who just codes". You have technical insides and experiences, that maybe no-one else has. Use it for good.&lt;/p&gt;

&lt;p&gt;What have been your experiences? What have been your success-stories and biggest fails?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>business</category>
    </item>
    <item>
      <title>A small refactoring example</title>
      <dc:creator>PHP and cigars</dc:creator>
      <pubDate>Thu, 21 Sep 2017 09:10:38 +0000</pubDate>
      <link>https://dev.to/phpandcigars/refactoring-php-a-small-example</link>
      <guid>https://dev.to/phpandcigars/refactoring-php-a-small-example</guid>
      <description>

&lt;p&gt;I'm currently reviewing a small piece of code of a new co-worker. As he comes back to work next week I will share a small example how to refactor the code here, so I won't forget to mention it to him.&lt;/p&gt;

&lt;p&gt;I found this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;mProductUnits&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$ret&lt;/span&gt; &lt;span class="o"&gt;.=&lt;/span&gt; &lt;span class="nx"&gt;hHtml&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;Clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$ret&lt;/span&gt; &lt;span class="o"&gt;.=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;RenderInfoRow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nv"&gt;$unit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;showUnit&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nv"&gt;$unit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;RenderPriceWithCurrency&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nv"&gt;$unit&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;AvailabilityMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;RenderInfoRow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$availbility&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="s1"&gt;'&amp;lt;div class="col-l-4 col-m-4"&amp;gt;'&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;div class="col-l-2 col-m-2"&amp;gt;'&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$price&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;div class="col-l-4 col-m-4"&amp;gt;'&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$availbility&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What problems do we have here? Hungarian notation? Well, yes, but that is my fault and is due to the framework i wrote. Besides that?&lt;/p&gt;

&lt;p&gt;Wright. The single responsability principle is hurt. Also Uncle Bob teached us, that one parameter to a function is ok. In this example it is absolutely possible to use only one parameter to the function RenderInfoRow()&lt;br&gt;
So lets see how this gets refactored in a first step:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;
&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;mProductUnits&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$ret&lt;/span&gt; &lt;span class="o"&gt;.=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;RenderInfoRow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$unit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;RenderInfoRow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oProductUnit&lt;/span&gt; &lt;span class="nv"&gt;$u&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="nx"&gt;hHtml&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;Clear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;div class="col-l-4 col-m-4"&amp;gt;'&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$u&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;showUnit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;div class="col-l-2 col-m-2"&amp;gt;'&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$u&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;RenderPriceWithCurrency&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;div class="col-l-4 col-m-4"&amp;gt;'&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$u&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;AvailabilityMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/div&amp;gt;'&lt;/span&gt;
    &lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This has more than one advantages. First: It's easier to read and less to write. But second (and in this case maybe more important): Now the IDE knows, that $u is of the type oProductUnit. So now you don't have to open the class to see the function-names. You get them presented as soon as you type $u in the function.&lt;/p&gt;


</description>
      <category>php7</category>
      <category>oop</category>
      <category>cleancode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Why I chose to create my own PHP7 shop-software (and I am happy with it)</title>
      <dc:creator>PHP and cigars</dc:creator>
      <pubDate>Wed, 21 Jun 2017 16:46:00 +0000</pubDate>
      <link>https://dev.to/phpandcigars/why-i-choosed-to-create-my-own-php7-shop-software-and-i-am-happy-with-it</link>
      <guid>https://dev.to/phpandcigars/why-i-choosed-to-create-my-own-php7-shop-software-and-i-am-happy-with-it</guid>
      <description>

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;Please excuse my poor english. I had to quit taking english classes in highschool because of an really bad teacher.&lt;/p&gt;

&lt;h2&gt;
  
  
  About my project
&lt;/h2&gt;

&lt;p&gt;Two years ago i started a new job. My employeer wanted me to create a new online-shop and gave me total freedom. As it is a side project for the company and mainly serves to explore new technology, ux and seo methods and has only to be profitable on the long term, I had the opportunity to create a nice piece of software and learn a lot during the way. I do not say the path I took was the right one, but it seemed to be the right one for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Create a fast, scalable, extendable multi-shop-software.&lt;/p&gt;

&lt;h2&gt;
  
  
  First decision: Language
&lt;/h2&gt;

&lt;p&gt;Yes, I was curious to try something new to me like Ruby on Rails or Django, but in the end it seemed a too big project for me to fail. I've seen projects fail because whole teams switched to rails without having experience with the language. So I sticked with PHP, that I first tried in 2001. I also was curious to try the new features of PHP7.&lt;/p&gt;

&lt;h2&gt;
  
  
  Second decision: Shop-software, PHP-framework or start (almost) from scratch?
&lt;/h2&gt;

&lt;p&gt;The goal was to create a fast loading, nice to customize web-shop. I first thought about trying Magento. A lot of competitors use Magento, so how could I create an advantage with the same software? At the end the slow speed was a weak point where I could gain points. I tried some others, but was not satisfied either. Today I would probably decide to try shopware. But the version at that time did not fit my needs.&lt;/p&gt;

&lt;p&gt;Also my experience with frameworks was not too good in the past. Maybe I got in contact with Symfony and CakePHP too early. I thought, that i spend to much time at looking things up and was often disappointed, when features where missing.&lt;/p&gt;

&lt;p&gt;So, i decided to do something stupid and create a new shop based on a conference talk. I had written several MVC-Frameworks before. The last time I wrote an framework was for my bachelor-thesis. So I decided to strip the basic object, list and datatype classes out and use them for my project.&lt;/p&gt;

&lt;p&gt;The mentioned conference talk was about creating a push-architecture instead of a pull architecture, where almost everything is static, cached content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Splitting everything up in App/Core
&lt;/h2&gt;

&lt;p&gt;As I wanted to reuse code and occasionally overwrite codes to customize code for a specific shop, I decided to adress everything over the App Namespace. So I have a lot of empty classes, that just extend the Core-classes.&lt;/p&gt;

&lt;p&gt;A usefully tool was the "Kaderschule" (cadre school). As I share my Surname with a socialist head of state I thought it was funny to make a pun of it and name the class creator skript like that. That script creates classes not only for one project, but optionaly for all projects I work with only one command.&lt;/p&gt;

&lt;h2&gt;
  
  
  Template-Engine vs. Renderer
&lt;/h2&gt;

&lt;p&gt;As I wanted to do all the fancy stuff that people are used theese days I thought that it would be a good idea to try out an template engine. Unfortunatly the possibility to overwrite parts did not seem very elegant. I will explain this in detail soon.&lt;/p&gt;

&lt;p&gt;So I did some research. I even went to the university library. All books (like 7 or 8 books) that had somehow web-development as a topic suggested the same: Use a Template-Engine.&lt;/p&gt;

&lt;p&gt;At the end I came up with an listing in Clean Code by Uncle Bob Martin. He used several renderer-classes to replace an output.&lt;br&gt;
Also it means that I have to write more code, I'm satified with the way I can navigate through an renderer and how i can overwrite and extend renderer-classes. &lt;/p&gt;

&lt;p&gt;Consider this listing:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function Render() {
    return
        $this-&amp;gt;RenderProductName()
        . $this-&amp;gt;RenderProductImage()
        . $this-&amp;gt;RenderPrice()
        . $this-&amp;gt;RenderAddToShoppingCartButton()
        ...
    ;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Remember that I want to create a code-base for several shops. The above function could be in an core-class ProductRenderer. Imagine, that for one of n shops i want to render a short summary of the user-reviews (a.k.a. stars) beetween the price and the add to shopping-cart-button.&lt;/p&gt;

&lt;p&gt;I can simply change the code to&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
        . $this-&amp;gt;RenderPrice()
        . $this-&amp;gt;RenderRatingssummary() // New function was inserted here
        . $this-&amp;gt;RenderAddToShoppingCartButton()
...

    protected function RenderRatingssummary() {
        return '';
    }

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and than I can implement the function in the corresponding class in the App Namespace that extends the core class. Using a template engine I would have to copy /paste this section. Even in a shop-software were you are not supposed to touch the core classes i would have to copy/paste that code. That is something I really needed to avoid.&lt;/p&gt;

&lt;p&gt;So IÂ´m very satisfied with this solution. Maybe I will still use an template engine to create some static domain specific content in the future, but for now that case never came. I really envy the readability of HAML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trigger pages to be pre-rendered.
&lt;/h2&gt;

&lt;p&gt;As mentioned, I wanted to create a super fast website. So every product, brand, category-page and so on is prerendered and cached in a memcache-storage. The memcache-entries contain the HTML that is replaced by user specific content like the shopping cart counter or the logged in icon. After the replacement the HTML can just be echoed.&lt;/p&gt;

&lt;p&gt;Everytime a product changes, the corresponding pages have to be re-rendered. That is archieved by creating Trigger, that just insert an object id and the object-type to an render fifo.&lt;/p&gt;

&lt;p&gt;A daemon checks regualary if there is data in the render fifo and then beginns to render pages and store the output of the renderers in the cache. That is actually not that complicated as if first seemed, but still created some mental friction, so I asked an old study-mate to help me with that part. In the end cleaning up some code helped me creating the main trick to create a fast online-shop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I do not say, stop using that framework or that shop-software. I just can say, that for me and my needs it was the wright decision. And if you want to try that too: IÂ´m not a genius. IÂ´m sure if you have the budget (I think that is the biggest problem in most companies) to write an own shop-software you can do it, too.&lt;/p&gt;

&lt;p&gt;I hope this article helped to encourage someone to just loose a little bit the fear  of creating something similar and to make clear that software is not magic. ItÂ´s simply hours and hours of coding.&lt;/p&gt;


</description>
      <category>phpframeworks</category>
    </item>
  </channel>
</rss>
