Category: Programming

Discover 3 Tips Every Developer Should Know in 2018

Discover 3 Tips Every Developer Should Know in 2018

In this post, I will help you discover 3 tips every developer should know. For the people reading this post who are hoping to learn how to program, no one is perfect, and we all make mistakes, so have fun while you learn. Everyone else, leave a comment below if you can relate or have any other tips!

Debugging

I think it is rare when code works as expected the first time you try it. Sometimes error messages seem very cryptic and are hard to understand, but if you read it carefully, it may give you some context as to what is wrong. Usually, you forgot a semicolon, and you’ll become very familiar with that error message, I am at least.

While you can Google your error messages all day long and find millions of results, they won’t always be helpful, so you need some tools to figure it out on your own. You are expecting your variables to contain specific values, so I usually check to see what is in those variables. Using console.log or var_dump can help you figure out where your code went wrong.

Sometimes you will have to dig a little deeper. So I encourage you to reduce the complexity of the error-prone code until the error goes away. You may want to make a copy of the files current state before you start removing lines of code.

Rick and Morty looking for something

Just remain calm, don’t stress, and use your brain. It may help if you step away from the computer for awhile. Maybe go for a walk or pet your dog.

Trial and Error

If at first, you do not succeed, don’t immediately ask for help, but do try it a different way. Your code may be getting too complicated, and it could be best for you to refactor it. Again, I suggest you step away and pet your dog if you get stuck.

I like to keep a log of what I’ve tried and when I tried it, why I thought it would work, and what happened. Doing this helps me keep track of where I was going with my thoughts. You don’t want to get a hunch and forget it; that’s a waste of your time.

You may need to go back to the planning phase and see if you still think this is the best way to approach the problem. I use pen and paper a lot when I’m working on larger projects. Our minds are incredible, but being organized helps me a lot.

Asking For Help

We all make mistakes. Sometimes, we think the error is not our fault, when in fact it is. Don’t be fearful of asking for help, but also, don’t let it be the first thing you do. Asking for help should be your last resort.

When you do ask for help, give enough information for people to understand the context of your situation, but don’t overload them with garbage. I often find myself typing up a question on StackOverflow when I realize what I did wrong. Even talking out the problem with a co-worker can help you understand what you did wrong. If you don’t have a co-worker, you can always tell your dog. They’re good listeners.

Conclusion

The title, Discover 3 Tips Every Developer Should Know, hopefully, encompasses the content of this post. Should you ever need any help, please feel free to leave a comment, or send me an email.

Advanced PHP is Actually Simple – Learn How Today

Advanced PHP is Actually Simple – Learn How Today

Advanced PHP methods, practices, processes, and everything else can be a bit daunting. If you find it hard to understand some of the documentation or tutorials out there, don’t worry, I can help! I struggled to learn some of the core concepts, but eventually figured it out, I hope I can help you learn with less of a struggle. Having a good development environment is a huge step in the right direction. For work, I use a Windows machine and a MacBook Pro. At home, I have a desktop running FreeBSD. Use whatever you are most familiar.

Packages

You don’t have to do everything yourself; this was a hard lesson for me to learn. There are groups of people who focus on a single PHP package. That package is going to be well written, tested, and hopefully documented. I suggest you use PHP packages when you can. You can browse the available packages on packagist. You will need to have composer installed on your dev machine. If you have an idea for a package, then read my post on creating a PHP package.

Autoloader

The autoloader isn’t magic, but it is very helpful when writing advanced PHP. It will conditionally include the needed PHP files based on the code being run. No longer will you need to have dozens of includes as the autoloader will handle most of them for you. Packages have a registered namespace that tells the autoloader where their files so it can load them. This allows you to easily instantiate a new object without having to include the needed files.

PHP Design Patterns

You’re only making it harder for yourself if you aren’t using design patterns. There are plenty of definitions of design patterns, and none of them make sense. When a definition is defined with other complicated words, I find it confusing. Below is a simple explanation of design patterns.

A design pattern is a way of structuring your code so it can easily be extended, enhanced, or fixed. Most advanced PHP applications will use a couple of design patterns. They’ll help keep your code organized and understandable.

I have written a few posts on different design patterns, such as the adapter pattern, dependency injection, and the factory design pattern. “Design Patterns: Elements of Reusable Object-Oriented Software” by Erich Gamma is an amazing book if you want to learn even more.

Security

There have been a lot of very public data breaches in the last couple months, so I will also cover some basic security tips. Whether your application is used by a couple of people or hundreds, you should always practice safe security. If your app uses a database, an API, or some other type of service, it could be vulnerable.

When you are writing information to your database, please use PDO. PDO is faster and more secure. PDO Tutorial does an excellent job of explaining everything clearly and concisely. Feel free to ask any questions in the comments below.

Another important aspect of application security is protecting against CSRF (Cross-Site Request Forgery). If I were to create an HTML form on my website and set the POST parameter to your website, how would your website know where the post came from? It’s a very difficult thing to do unless you use a CSRF token with your forms. When a user sees a form, you also generate a CSRF token. You add the CSRF token to a session variable and to a hidden input field that is part of the form. Then when the user submits the form, you can check the hidden input field data against the session variable. If they match, then you know they submitted the form from your site.

Visit the OWASP website if you would like to learn more about security.

Advanced PHP Conclusion

Programming is all about solving problems. We take a big problem, break it into smaller problems, solve the smaller ones first, and then we’ve solved the big problem. Keep trying to make your code smaller, simple, and elegant. Programming is art for logical people like yourself. Keep being curious. Let me know in the comments below if you have any questions. I would love to help.

Skeleton Repo for PHP, JavaScript, and SCSS

Skeleton Repo for PHP, JavaScript, and SCSS

I work on a lot of different projects, and each one is unique in its own way. I often find myself installing packages manually and then configuring them. It seems like I repeat myself quite a bit, but the requirements of each project vary ever so slightly. In an attempt to prevent myself from repeating the same tasks over and over, I’ve started working on a skeleton repo that contains nearly everything I would need.

What I was doing

Most of my projects are built in PHP and augmented with JavaScript and SCSS. Occasionally I’ll make a project solely with JavaScript. So I would have to run the following commands:

  1. composer init
  2. composer require silex\silex illuminate\database
  3. npm init
  4. yarn add webpack babel-core … and many more

Then I would have to do the following:

  • Configure my composer.json to use PSR-4 autoload for my namespace
  • Create my folder structure
  • Create some interfaces, classes, and models
  • Configure webpack to use my folder structure
  • Import my SCSS

Doing all of this over and over is a waste of time.

Creating a skeleton repo

My decision to create a light skeleton repo has saved me time. Since it is light, it is very easy to scale it back to what I need. However, if I need to add more, I can do so easily. It turns out that I’m quite good at creating a skeleton repo since I’ve done it so many times. By carefully planning and using the steps above, I had one created in about a day. I’ve continued to refine it and add more features.

Conclusion

I’m sure there are some very elegant solutions on there that do what I need, but I enjoy creating these solutions for myself. Perhaps I’ll end up using something someone else created, but I hope that I’ll have a greater understanding of what they’ve done.