namespaces part 4.1 (what namespaces don't fix (part 1)) - david coallier

namespaces part 4.1 (what namespaces don't fix (part 1)) - david coallier namespaces part 4.1 (what namespaces don't fix (part 1)) david coallier wednesday, october 3. 2007 posted by david coallier in php at 12:37 | comments (5) | trackbacks (0) namespaces part 4.1 (what namespaces don't fix (part 1)) welcome back to another namespaces smallish article. over the past few years i have noticed people saying a whole lot of things about namespaces (obviously people that don't use namespaces and wanted something to blame their poor design decisions on). anyways, after posting a few articles about namespaces and now that the patch has been ported to the php 5.3 branch, people are actually starting to use it. the side effects of people (without too much knowledge or thinking about the implementation of namespaces) is that they are actually realizing that namespaces are not the promised land. ok let's get moving, i'll start with the part one of my "what namespaces don't fix".. many people seem to have wanted namespaces in php because their class names are too long. for instance, people complain that projectname_package_category_classname is too long, so they would love to have namespaces to make that shorter. when you actually consider the issue in a simple example: (let's create a namespace and use it)--namespace projectname::package::category;class classname{ public $class = 'ohyesszzz';}---eof--- (next file, we now need to use that class with the current implementation of namespaces (consider that it's been included already ok?) // // we import is 'as' something to make sure there are no conflicts with classname // import projectname::package::category::classname as ppcclassname; $new = new ppclassname; ok, we did it... was long wasn't it ?... oh well now let's try the good old fashion way with prefixing...class projectname_package_category_classname{ public $class = 'ohnoes';} (now let's instantiate it (assuming it's been loaded/included already)) $new = new projectname_package_category_classname; namespaces are not making your classes shorter for those who are lazy and hopped their open source application would work without a conflict anywhere. do not consider the namespaces a way to make your class names shorter please. some will say that the "as" makes it shorter but the amount of characters you have to type to get there is actually more. question remains, after having seen a lot of entreprise and open source frameworks that are coded like.. hmm crap.. how will the php community and companies manage to screw up a way to code in a more clean and organized way? bets are opened please note that i am not saying that the current namespace implementation is not good, i am just stating that some of the reasons why a lot of people wanted namespaces are not totally the good reasons. i will be following with a few more articles about demystifying the namespace myths..in resume: namespaces are not at all about making you type less, but an additional structural element that actually requires you to type often more. trackbacks trackback specific uri for this entry no trackbacks comments display comments as (linear | threaded) in the case of namespaces you have x + y + 8 chars for initialisation where x is chars in namespace and y is chars in alias. each time you invoke you then have a further y chars for a total of: x+8+(n+1)y in the case of non namespace you have x chars (although you ommitted the required include in that case) per usage. so nx now it is clear that in most trivial programs this equation will in both cases be dominated by n. which means that if y < x then you will end up typing less for a given value of n. picking y small makes this value typically in the range of 2-3 #1 mr c on 2007-10-03 15:41 (reply) well, it does "shorten" them when used more than once and, the long part can be on a different line so it is easier to stick to the 80-char recommendation example (yes, perhabs not a really usefull one): if (new ppclassname::dosomecheck()) { $new = new ppclassname(); } question: does this work too? namespace projectname::package::category; class classname { function __construct() { $class = new otherclassinsamens(); } } if yes, this will also shorten what you have to type... ps: that "geshi-stuff" is wrong documented ([/geshi] instead of [/lang] and it does print a visible on every line..) #2 sascha on 2007-10-03 15:56 (reply) hmpf: " ... it does print a visible "br-tag" on every line" (perhabs in preview mode only) #2.1 sascha on 2007-10-03 16:00 (reply) david, take a look at any of the code inside pyrus. i'm using class names on nearly every line. for instance, when you are using class constants, this can result in completely unreadable code - and it requires the full class name. throwing exceptions for errors (which can occur regularly throughout well-written code) also results in many calls to the same long-ass class name. in short, your example doesn't really have anything to do with the php 5 development i've been experiencing, and namespaces will make a huge difference in readability and maintenance for the code i've worked with. #3 greg beaver (homepage) on 2007-10-03 21:05 (reply) hey greg, ok so i ask you this. imagine we have a framework with two plugins. the first pluging is in the namespace fmwone::package::date and the second package in fmwtwo::package::date you will have to import them and alias them using different alias right? (otherwise you get errors). so one will be imported as date and i don't know why, but i predict that some people will also import the second one as date and will see the same problem as the pear vs php problem a while back. please note that i am not saying that the current namespace implementation is bad, i consider good if you use it correctly. it will help a lot making very clear and structured code. however, as i have read on blogs and random articles (even heard on some irc channels) that aliasing would solve everyone's problem. as you say, with the php5 development you have been experiencing, it will make a difference. but i say it again, people have to use namespaces for the good reasons and not be blinded in ignorance. again i say it, the series of blog posts i am doing is to "inform" people. the one right now says that it doesn't "solve" the long name and class conflict issue, but the next one might be about namespaces good practices and/or general code organization (wink)(wink). #3.1 david coallier (homepage) on 2007-10-03 21:49 (reply) add comment name email homepage in reply to [ top level ]#1: mr c on 2007-10-03 15:41 #2: sascha on 2007-10-03 15:56   #2.1: sascha on 2007-10-03 16:00 #3: greg beaver on 2007-10-03 21:05   #3.1: david coallier on 2007-10-03 21:49 comment enclosing asterisks marks text as bold (*word*), underscore are made via _word_.standard emoticons like :-) and ;-) are converted to images.you can use [geshi lang=lang_name [,ln={y|n}]][/lang] tags to embed source code snippets   remember information? subscribe to this entry   calendar november '07 mon tue wed thu fri sat sun       1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30     links on this site.. about rants agora friends davey shafik pierre-alain joye amir helgi Þormar chris shiflett google is your friend too! forgot you? tell me.. hagfish alias 007 hagfish ben ramsey family alec coallier (brother) archives november 2007 october 2007 september 2007 recent... older... categories architecture xsl general francais java gwt pear php zend_db sql all categories syndicate this blog rss 0.91 feed rss 1.0 feed rss 2.0 feed atom 0.3 feed atom 1.0 feed rss 2.0 comments blog administration open login screen design garvin hicking, icons tango project alec coallier

Acceuil

suivante

namespaces part 4.1 (what namespaces don't fix (part 1)) - david coallier  Q-fix - home computer support  LUX ELEMENTS®- FIX - Tableau de chevilles  Mods Warlords v2.08 Hotseat Fix Civilization 4 : Warlords  Mod XX Century 2.11 Mi24 fix Civilization 4  Swarovski Hot Fix and Flat Back Crystal Rhinestones ...  The Hindu : International : Astronauts fix solar panel  Paroles Can You Fix This - Kate Ryan - Musique Ados.fr  Mac Rumors: Apple Acknowledges iMac Freezing Issue, Fix In Works  Huber Technology: Fix-Rail® Erweiterungselement  Decapitation Victim Tries To Fix Eyes - Health News Story - KGTV ...  SPACE.com -- NASA Eyes Space Shuttle Fuel Tank Fix  Flame Fix - Gas & Oil boiler service & repair & solar heating ...  Acheter et Telecharger Fix-It Utilities sur Softela.fr, N°1 ...  Télécharger Patch "Computer Player fix" pour Age of empires 2 ...  [Suggestion] - Section sécurité et fix - Forums Joomlafacile  Sugar Fix - Sweets and Candy - UK Sweets, US Candy, Lollies, Jelly ...  Zirh FIX – Gel atténuant pour imperfections du visage – Comptoir ...  Télécharger Avi Fix Repair Joiner. Fixez les dossiers d'avi de ...  BUG FIX TRANSPARENCE PNG IE (SIMPLE) png, simple, pngfix, iexplore ...  Adobe - Photoshop : For Macintosh : Mac OS X Keyboard Shortcut Fix  SKI+FIX+CHAUSSURES A 20 euros LE TOUT. - achat billets, loisirs ...  Redirect page  FIX-SAINT-GENEYS, une reproduction de  Lèvres Fix'Intense Tenue 10 h - Embellisseurs des lèvres - Zlio.com  Télécharger Fix My Registry 2.3 sur Ratiatum.com - Média ...  Profil de Fix (Admin)  Fix It with Fix  Skirando -- Compro-Vendo - Vends Ski dynafit+fix TLT + peaux  Bug (fix) in Firebug's Net Panel  Futurist: To fix education, think Web 2.0 Tech News on ZDNet  Attelage fix  Fix My Pages - FixMyPages.com - Web Page Repair  puericulture - sorties - siège auto noir bebe confort créatis fix ...  We fix IT  NASA delays spacewalk to fix solar wing International Reuters  iFixit: iPod, iBook, & PowerBook Parts and Accessories  Robert M. Ball - A Social Security Fix For 2008 - washingtonpost.com  AirNav: Fix Information  Pritt World: Multi-Fix  Paul Fix - Photos  Les Forums de l'OGSTeam / [FIX]Problème PHP 5 et Ogspy // session  Baby on the move : Coussin de relaxation et d'allaitement Form Fix  Fixatif flexible en spray "Fructis-Style Pure Fix Spray"  FIX in Las Vegas, NV - AOL City Guide  Reifen Sommerreifen Winterreifen Ganzjahresreifen - Reifen-fix.de  Microsoft changes mind, agrees to fix IE's URI handler  Zieh-Fix® Premium  Atreid : Produits > Logiciels > Modules externes vidéo - Film Fix ...  Fix Showproductions BV  Yes, the universe looks like a fix. But that doesn't mean that a ...  IBM - 6.0.2.23: WebSphere Application Server V6.0.2 Fix Pack 23 ...  Sommier LATTOFLEX LT15 Fix 2 pers. 140x200 Ferme / La Compagnie du ...  A Program That Can Fix Dead Pixels On Your LCD Screen.  Traduction Coldplay Fix You lyrics - musique traduite  FIFA KULTE, FCDB XP 2003 Fix 1.01  Foreign Policy In Focus Global Warming: The Quick Fix Is In  EASY FIX - Espace bébé & puériculture  Russia's food prices The big fix Economist.com  Fix the Home - Home Improvement & Home Maintenance Articles  eBay.ca : WINDOWS REPAIR FIX HARD DRIVE RECOVER LOST PASSWORD ...