Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

3/16/13

Why doesnt ObjectiveC have namespaces? Stack Overow

Why doesnt ObjectiveC have namespaces?

WhydoesntObjectiveChavenamespaces?Itseemslikeasimplefeaturethatwouldmakesomeclass namesmorereadable( A V M u t a b l e V i d e o C o m p o s i t i o n L a y e r I n s t r u c t i o nanyone?)andaxethesilly letterprefixesonclassnames.Isthismainlybecauseofbackwardscompatibility?Isitharderto implementnamespacesthanitseems?


objectivec namespaces

askedNov29'10at10:33 zoul 38.5k 8 86 154 Forwhatit'sworth,Iwouldn'tpreferNeXTSTEP::ArrayoverNSArray.Sillyasyoumightfindtheprefixthing,I thinkthefactthatthenamesdon'tcontainanysymbolcharactersfitsnicelyintothesentencelikestructureof theObjectiveCsyntax.w.mNov29'10at11:24 @w.m:Butyou'sdreaditas"Nextsteparray"not"Nextstepcoloncolonarray"inmuchthesamewayasyou read o b j e c t A t I n d e x : ias"objectatindexi"not"objectatindexcoloni".Thepointismootasfarasthe NSclassesareconcernedanyway.Youcan'tmovethemtoanewnamespacewithoutbreakingallexisting Cocoasoftware.JeremyPNov29'10at11:40 Also,youwouldn'treferenceitas N e x t s t e p : : A r r a yeachtime,you'dhaveone u s i n g N e x t s t e p ;andthen justreferenceitas A r r a y,unless therewasanambiguityandthenyou'dfullyresolveit.Itwouldactually makethecodecleanerandmorereadable.chaiguyMar1at22:22

2 Answers
Idon'tknowtheanswerbutIsuspect"it'sharderthanitlooks"isprobablyit.Youwouldhaveto introducesupportinthecompilerandlinkerinawaythatdoesn'tbreakexistingsoftware.Andwhilethis isobviouslypossible(C++hasalreadydoneit)presumablythetoolchainteamhavehadhigher prioritiesontheirplate.e.g.intherecentpastwehavehadgarbagecollection,GCD,blocksand ObjectiveC2.0appearsowecan'tsaytheyhavebeendoingnothing. NamespacesupportistheonethingthatIwoulddearlylovetoseeintroducedtoObjectiveC.
answeredNov29'10at11:33 JeremyP 33.7k 3 29 51

Idon'tknowifyouwanttoknowifwanttoknowsomeofficialdecision.Butnamespacelikemanyother featurearechoice,choicemadebythelanguagecontributor.PHPonlyrecentlyintroducedNamespace, andforexampleJavausepackagethatactlikenamespaceorpythonusemodules. Ithinkthatthereisanoverheadinnamespaceimplementation,mainlybecauseObjectivecis dinamicallytypedsoatruntimeyouhavetomakesomechecktoresolvethenamespace,toresolve defaultbehaviour,etc..andIcansupposethatbecauseObjectivecisalsousedinembedder enviroment(AKAiPhone)speedisveryimportant.

stackoverow.com/questions/4302872/whydoesntobjectivechavenamespaces

1/2

3/16/13

Why doesnt ObjectiveC have namespaces? Stack Overow

You'vetowrapeverythingi'vesaidinabigIMHOD
answeredNov29'10at11:31 LucaBernardi 1,569 1 9 22

3 Itwouldbeenough,Ithink,toprovidenamespacesupportforclassnames.Thesewouldbemangledin
somewaysothat,atruntime,therewouldbelittleornooverhead.JeremyPNov29'10at11:36

Not the answer you're looking for? Browse other questions tagged objectivec
namespaces or ask your own question.

stackoverow.com/questions/4302872/whydoesntobjectivechavenamespaces

2/2

You might also like