gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

Namespaces #210

Closed RWOverdijk closed 12 years ago

RWOverdijk commented 12 years ago

Hi. I don't know if I should be asking this using the issue system on github, but I have no idea how to otherwise contact anyone.

I was wondering if this whole "namespaces suck" attitude is still the case. I personally believe that a lot of arguments used against them are invalid. It'd be a shame if redbeans were to stay unnamespaced (in my opinion) and I'm curious if it will.

This is in no way an attack. I'm genuinely curious.

gabordemooij commented 12 years ago

Hi.

If you like to use namespaces with RedBeanPHP you can use the namespacer: space.php This would basically be the same as a minimal namespace solution, i.e. RedBean/RedBean_OODB etc. Concerning the attitude: feel free to change my mind. Why should RedBeanPHP use PHP backslash namespaces? Why are the arguments (including those http://pornel.net/phpns/) invalid?

Cheers, Gabor

RWOverdijk commented 12 years ago

Let me start off by saying that I hate the backslash separator. I'm used to it now, but I really don't like the fact that it's a backslash. I'd rather see a forward slash (path separator).

Namespaces do more than just take up space and prevent naming collisions. It's a way of dividing actual packages from each other (if you wish to call them this).

I'd like to ask you to start with this article written by Matthew. You've probably heard of him :p

I do sort of agree with some points in that article (Yes, believe it or not I did read it before opening this issue. I also already knew about the namespacer thingy.) and mainly speaking about the flaws and reserved keywords. But namespaces are a recent addition so I can see this being dealt with in the future. Even if the don't, who uses the namespace Split, seriously. I thought this was a very good argument, with an invalid example.

If that article is not enough, then let me know what's holding you back. I'll try to tackle those for you. There's a reason they were added to the language, and why they're being used so heavily. :)

gabordemooij commented 12 years ago

First, your own argument:

The fact that many people use a technique does not make it better.

Now let's talk about the arguments provided by Matthew:

  1. Code Organization. Invalid argument. The separator reminds Windows users of a path, to a Linux user it looks like a regular expression delimiter.
  2. Readability. What's more readable than: 'Model_Book' ? You know it's a book, you know it's a model. It does not have new syntax; it's just a name. Even better, it's consistent. You can do a 'search-replace-all'. Instead Matthew ends up with three different names for single class: the original class name, the use-name and the alias (probably more aliases). To me that's LESS readable.
  3. Dependency tracking - "Importing helps you make dependencies explicit". If you need additional code to clarify other code things have gone terribly wrong; use better names or comment your code Matthew.

In general, my philosophy is to use as little language features as possible, I am a minimalist. Given a complex solution and a simpler one I prefer the latter. I adopt a more complex solution only if the benefits outweigh the costs significantly. For instance I have embraced closures because they shorten code and remove inter-object wiring. Also they add almost no additional syntax; great value.

Concerning Matthew, I attended his talk "Beautiful Code" at Dutch PHP Conference 2012 this summer. We seem to have different opinions about "Beautiful".

RWOverdijk commented 12 years ago
  1. Alright. Well, I thought that a regular expression delimiter was a forward slash, where backslashes are used for escaping. But that might be me.
  2. I know, it is readable, but it's less logical to me. But I guess that's just personal preference.
  3. Well, that's meant for larger projects. Imagine not using namespaces and working with a bunch of packages through composer. That might make it a bit messy.

I also believe that when using an IDE, it's nice to be able to "browse" through namespaces so you can more easily select packages. I can just select a namespace and see what it contains. Underscores can't do that.

Initially I shared your opinion, I hated namespaces. But once I started working with them I started to like them. And now, I actually love the way they work. Explicitly using classes means that you always know what's being used, and what's not. And you don't end up with new Some_Extremely_Long_Class_Name();, as you've used your classes and can now use just the classname. Sure, you could setup aliases, but that doesn't count as that's more complex and less appealing.

Using namespaces is something that brings structure as it really creates separation. Underscores just let you believe that there are namespaces.

Anyway, I'm going to stop trying to convince you now :) I've decided to go with Doctrine2.

Best of luck!

Freeaqingme commented 12 years ago

@gabordemooij Your first two points relate to aesthetics. That's a given with the php language, and imho shouldn't be a deciding factor. Also, it was thoroughly discussed on the php internals group, and well argumented: https://wiki.php.net/rfc/namespaceseparator

In general, my philosophy is to use as little language features as possible, I am a minimalist.

I would suggest writing your application in Assembly. I personally like to keep my application as maintainable as possible. Even if that means it becomes twice as big.

gabordemooij commented 12 years ago

@Freeaqingme Minimalism is a powerful tool to keep things simple, maintainable. Assembly code is not very minimalistic I can assure you (I have written a pacman clone in x86 assembler once ;)). Smalltalk would be. I will check the PHP wiki discussion, sounds interesting.

    • yes my mistake, bad example. Arguments still holds, backslash is a Windows file system separator, so Matthew's claim is false.
  1. this whole discussion is about opinions ;)
  2. I don't see why it would be messy. Using no namespaces would be messy yes, but that is not the case here, RedBeanPHP uses Poorman's namespaces

The IDE thing IS a good argument though. I didn't think of that. Noted.

Concerning Doctrine2: Ok, well I hope you like it. Good luck.