Image for post
Image for post

Imagine you have a service responsible for returning search results and you want to use this service in your APIs, Admin area, and Homepage but you want to replace blank spaces with a dash in API response (or other changes) and not in another part of your application.

We gonna use Bridge Pattern to achieve this but before getting started please have a look at the Bridge pattern class diagram


Tips for PHP developers to write shorter and high-performance code

Image for post
Image for post

For-Loop

I’ve frequently seen developers make a common mistake in ‘for’ loops in their PHP projects. As an example:

At the first glimpse, this code looks ok, but there is an issue with the performance! In each iteration, the ‘count’ function will be executed and if you are having a large array it will cause a performance issue.

To fix this issue, you can easily calculate the count of the array before ‘for’ or inside for(). Have a look at this code:

A slick way to return a Boolean

This function is too long, let's reduce it to just one line!

We could just return…


Image for post
Image for post

I’m sharing my experience with a task assigned to me one year ago. It was a new feature in our system and I was responsible to finish it bug-free and in a short time.

The product owner had asked me to create a page to generate discount coupons (random string coupon, fixed string coupon). When I started analyzing the requirements, I guessed in the future, they may ask for generating the coupons in a different way such as the generation of just numeric coupons.

I’m going to share my code with you but before getting started, I would like to…

Amir Etemad

Backend Developer, Flexitarian, Developer @Enuygun.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store