About class naming over-simplification

Naming a class as ProductProperties, instead of simply Properties despite the namespace refer it to be in the Product namespace, does NOT defeat the purpose of the namespaces.

Namespaces are supposed to prevent clashes in class naming, to prevent ambiguity at a auto-loading level. They do not prevent ambiguity at a development level.

If at development I see a class named Properties, I will assume it to be Properties. Would any dev go look at the top of the file for the “use bladibla” to make sure about what class it is? I dont think so. However, that Properties class might actually be the ProductProperties, or the CategoryProperties, or something else. So a class name should be as accurate and unambiguous as possible, independently of the namespace.

Bottom line: If its a Properties class, name it Properties, but if it is a ProductProperties class, name it ProductProperties!

DDD.1 – Crunching knowledge

Developers and Domain Experts collaborate, discussing the Domain Experts knowledge, distilling it into all, and only, the knowledge relevant to the project.

The objective is to end up with a model of what the application should do, how it should do it, and what the technical implementation should be.

Continue reading “DDD.1 – Crunching knowledge”

SEO URLs: hyphen vs underscore

This is a recurring question and I don’t always remember why I prefer hyphens, so here’s the answer:

Consider using punctuation in your URLs.
The URL http://www.example.com/green-dress.html is much more useful to us than http://www.example.com/greendress.html.
We recommend that you use hyphens (-) instead of underscores (_) in your URLs.

Source: Google support

It turns out that, at least for google, the underscore works as a concatenator for words.

There’s also a video of Senior Google Engineer Matt Cutts, where he explains exactly this.

According to YEAH! Local, another reason, aside for the Search Engine Optimization is this:

If your URL contains underscores the link will look similar to this:

http://www.tips_for_instant_weight_loss.com (http://www.tips_for_instant_weight_loss.com)

Whereas if your URL contains hyphens, the link will look similar to this:

http://www.tips-for-instant-weight-loss.com (http://www.tips-for-instant-weight-loss.com)

A user may mistake the underscores for spaces, as the underlining in the link hides the underscores. On the other hand, hyphens are clearly visible, so users are more likely to remember to type them.
So, the use of underscores in URLs impacts usability as well as SEO.

Source: Woorank

And if you are interested in the WHY it works this way, here it is Matt’s post about the WHY.

Creating relationships between entities with Symfony2, Doctrine and yml

So I’m starting a new project now, I’ve set up the logger, I’ve set up the mailing, and now it’s time I start to set up the model layer with Doctrine. In Symfony2 you can choose to have the configuration of this layer in xml files, yml files or as annotations directly in the entities classes. Personaly I find xml files too verbose, and annotations put logic in the entities which makes them less readable and if we want to change ORM we will have Doctrine configurations in entities that do not deal with Doctrine, so I prefer to have the configurations in yml files. Symfony has some documentation on how to set this up, but its not complete, as far as I can remember it only has documentation about one to many relationships, but in real life situations we rarely find only those types of relationships in a DB schema, so here I will document how to configure one to one, one to many, many to many and many to many to many relationships.

Continue reading “Creating relationships between entities with Symfony2, Doctrine and yml”

How to set up a proper logger in Symfony2

Properly setting up a logging system for your application is essential for its maintainability, debugging and monitoring.

That being said, what we ideally want in a logging system is the following:

  • Only log our application messages, don’t log symphony stuff;
  • Log to a different file per environment (dev.log, test.log, prod.log);
  • Log to the console, when we run the app through the command line. This way we see feedback immediately, we don’t need to have another window open with tail -f dev.log. With this we can also automate the feedback the app gives back tot he user;
  • Also log specific jobs to a specific file, so we have a log per job;
  • On Production it should also send us an email if something goes wrong.

Continue reading “How to set up a proper logger in Symfony2”

Setting Apache and MySQL to start/shutdown manually

Starting Apache and MySQL will take some additional time, but other than that if you give these services nothing to do they won’t impact your system performance (they won’t eat much CPU in idle; and any memory they need goes to swap). However, and you can probably do this through the GUI as well, here goes with a few commands to switch them to manual.

Continue reading “Setting Apache and MySQL to start/shutdown manually”