if($this->user->balance>$amount && $this->user->activeLoan===0){ $this->user->balance -=$amount; //widthraw amount; }
Keeping your code clean
Samuel James

This would be easier to read if you weren’t pathologically parsimonious with whitespace!

EDIT: He fixed it in seconds! Good going.

Look at this sub-expression:


On first glance, you see three > symbols — it takes some little thinking to realize that one of these things is not like the other two. Which are the variables? You have to piece it together. A little extra work per line of your code — not a good idea.

Spaces surrounding the variables, and suddenly it’s instantly clear what’s going on — it’s a comparison statement.

$this->user->balance > $amount

Now, the original code is probably clear to you. But if your code is successful, you hope it will be read by a lot of people. Some of them will be beginning programmers who are not so used to reading code, some of them will be experienced programmers who aren’t familiar with your language (I am in that category), some of them will be talented programmers in a hurry, some of them will be visually impaired.

You don’t want to dumb your code down, but surrounding variables and “words” by spaces — just like you do in all human languages — makes your code more readable to a large class of people.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.