Blog
Sat, 18 Sep 2010
I find myself in this pickle from time to time. When I engage a project, too late to find out it was built by monkeys. Sometimes I go through code and It blows my mind how sloppy some of these chimpanzees are. How did they ever get a position programming in the first place? Their skills were certainly untested. I would not be surprised at them eating bananas during their interview.
Building upon someone else's code is never very enjoyable, it's always a pleasure to start from scratch. The problem I see is that nobody I come after follows any standards. Why use gif's and png's in projects? Pick one or the other. Why have duplicated files all over one project? Clean it up. Why have Client-Side JS logic scattered throughout random pages? Dedicate a folder for JS usage. Why name everything on a whim? Use a naming convention. Why not comment written code? Comment it!
I see three categories of programmers. Here they are:
1. The slob - This person cares nothing about their work and is only their for a paycheck. What happens afterwards matters little to them, they are just putting their time in. More bugs means a more secure job, since they are tailored to this persons way of writing illogical code, they are the only ones who can fix it.
2. The scatterbrain - Although these programmers tend to be very smart and the best at solving complex problems while getting things done quickly - they are all over the map with what they are doing. They do not consider another person may have to work on their own work at some point, and if they do, they usually aren't very good at making it usable for the next guy despite what they may think.
3. The slowpoke - These guys are very organized and can explain why they did what they did, however they work very slow and often look bad when crunch time comes. Their greatest fault is they want to be a perfectionist and they waste too much time on minute details. They can also be too picky.
If there is a programmer that possesses number's 2 and 3, they would be the perfect programmer. I have not met one yet, not even myself.
Sat, 18 Sep 2010
Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
— Bill Gates
The object-oriented model makes it easy to build up programs by accretion. What this often means, in practice, is that it provides a structured way to write spaghetti code.
— Paul Graham
Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves.
— Alan Kay
Complexity kills. It sucks the life out of developers, it makes products difficult to plan, build and test, it introduces security challenges and it causes end-user and administrator frustration.
— Ray Ozzie
Good code is short, simple, and symmetrical - the challenge is figuring out how to get there.
— Sean Parent
One of the big lessons of a big project is you don't want people that aren't really programmers programming, you'll suffer for it!
— John Carmack
An organisation that treats its programmers as morons will soon have programmers that are willing and able to act like morons only.
— Bjarne Stroustrup
In programming the hard part isn't solving problems, but deciding what problems to solve.
— Paul Graham
The purpose of software engineering is to control complexity, not to create it.
— Dr. Pamela Zave
Complexity has nothing to do with intelligence, simplicity does.
— Larry Bossidy
Simplicity is hard to build, easy to use, and hard to charge for. Complexity is easy to build, hard to use, and easy to charge for.
— Chris Sacca
Simplicity is the ultimate sophistication.
— Leonardo da Vinci
Debugging time increases as a square of the program's size.
— Chris Wenham
When I am working on a problem I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong.
— R. Buckminster Fuller
The best things are simple, but finding these simple things is not simple.
- Anonymous
My definition of an expert in any field is a person who knows enough about what's really going on to be scared.
— P. J. Plauger, Computer Language, March 1983
What I cannot build, I do not understand.
— Richard Feynman
Sat, 18 Sep 2010
These are some OO Design Principals which will help you in a variety of situations. They are 'rule of thumb' practices, and considered the best practices.
| Command Query Separation |
Every method should either be a command that performs an action, or a query that returns data to the caller, but not both. |
| Hollywood Principal |
Don't call us, we'll call you |
| DRY |
Don't Repeat Yourself |
| SRP |
A class should have only one reason to change |
| Program to an Interface not an Implementation |
Do not mix relationships to classes, instead mix them to interfaces. |
| OCP |
Open/Closed Principal. Classes should be open for extension but not modification |
| DIP |
Dependency Inversion Principle: Depend on abstractions rather than concrete classes |
| YAGNI |
You Aint Gonna Need It Later. Always implement things when you actually need them. |
| COC |
Convention over configuration. Decrease the number of decisions that developers need to make, gaining simplicity without losing flexibility. |
| Encapsulation |
Hiding information that could potentially be overwritten |
| Encapsulate what Varies |
Separate what varies from what remains the same. |
| KISS |
Keep It Super Simple |
| Loose Coupling |
The Dependency to which each module relies on each one of the other modules. |
| Interchangeability |
The ability to replace an object by another object without affecting code using the it. |
| Favor Composition over Inheritance |
Classes become polymorphic and code is reusable by including other classes which implement the desired functionality instead of through inheritance. |
| Fragile Base Class |
Seemingly safe modifications to a base class, when inherited by the derived classes, may cause the derived classes to malfunction. |
| Common Closure Principal |
Classes that change together must be placed in the same packag |
Sat, 18 Sep 2010
A lot of programmers I've seen start out with a great start, errors and sloppiness are to be expected with a new language. However, when the individual finally gets comfortable doing something a certain way that works for them, it seems some stop excelling. In my opinion, it's better to go in depth with fewer subjects than broad on many topics which causes a lack of depth.
In an Object-Based language, here is a chart that I see among much code:
If you excel beyond the halfway point there, you will potentially become a very good programmer. The picture below shows the phases you may go through in the simplest of steps with a visual example of a code structure. One thing that could be easily overlooked below is that an OOP/OOD developer may have a lot of Spaghetti code mixed in with Phase 2 and Phase 3, that's not good!
Something like this may take several years to get to efficient at, but it's worth it! Programming should be thought of as architecture more than "lines of code", or "just so it works".
Here is my personal recommendation. If you'd like to grow faster, this is a fantastic book that I recommend reading several times over, it's called The Pragmatic Programmer. I own it, and it's possibly one of the best books to help you improve your applications. So check it out!
Sat, 18 Sep 2010
Here is a Singleton pattern in PHP by example. Singleton basically means, 'A single copy'. In order to accomplish this, we must use static methods. Otherwise, the class could be re-instantiated and the "Has Been Called" flag would be reset, destroying our goal. An example of using this could be for loading a database object and being certain its only been loaded once.
My Advice: Use Singleton's sparingly.
/**
* Obviously you don't name a class Singleton, name it for whatever it applies to.
*/
class Singleton
{
/**
* @var boolean $_loaded Whether or not this class has been called
*/
private static $_loaded = false;
/**
* Loads whatever you plan on loading only once
* @return mixed Either False or Object, but you can return anything you like.
*/
public static function load()
{
if (self::$_loaded == true) {
return false;
}
return new itemToLoad();
self::$_loaded = true;
}
}