arboleya / coffee-toaster

Minimalist build system for CoffeeScript.
114 stars 23 forks source link

Start namespace with an uppercase letter #50

Closed madundead closed 11 years ago

madundead commented 11 years ago

Hi! I really like your project. But I mentioned a little but annoying thing while trying to enhance my old project with Toaster.

So I already had a namespaces implemented in my project and they were all starting with capital letters. But Toaster rewrote them starting with the lowercase as expected matching my dirs structure. I use backbonejs and that's the reason I was naming my namespaces this way, in order to match backbone style.

Is it possible to have an option responsible for namespaces naming format?

I'm new to node/coffee stuff so I'm sorry if this proposition is against some convention or community rule.

arboleya commented 11 years ago

Hi, good to know you're enjoying it.

Well, I never heard of anyone using namespaces with capital letters, which can easily become CamelCased if you have a folder called my_beautiful_ns, which is even weirder. I don't really know if it's because of some convention, but I can tell that it's kind weird. Generally, Capital / CamelCased names is used to classes only.

It helps you to identify wherer you're walking through a namespace of if you have reached your ending point, it is, your Class.

app.models.Model sounds ok, but App.Models.Model would look confusing.

As the namespaces are used in the core for resolving dependencies, ordering things, searching for circular loops and so on, it's not a trivial feature to implement since it'd affect many parts of the system, and just the tests to cover it would demand some hours or days too.

For now, my answer is no, it's not going to be a part of the core. Anyway, I'll left it open for a little until I can think clearly about it. You can always make your own fork of the project and implement whatever you want though.

In this meanwhile, I encourage you to do a tricky search/replace in your existent code if you're really up to use Toaster. Maybe it worth it? :)

madundead commented 11 years ago

It helps you to identify wherer you're walking through a namespace of if you have reached your ending point, it is, your Class.

Yeah this makes perfect sense.

But as I said - I was just trying look similar to backbone

var Note = Backbone.Model.extend({
   ....
});

Anyway I'll go with search/replace for now. Thank you!

arboleya commented 11 years ago

Oh well, good pointed, Backbone uses it, but Backbone doesn't have namespaces in the plural, it has only on top-level namespace that holds everything under it. Right?

Is that your case? Is everything under one single-point?

madundead commented 11 years ago

Backbone uses it, but Backbone doesn't have namespaces in the plural, it has only on top-level namespace that holds everything under it. Right?

Yup.

Is that your case? Is everything under one single-point?

Well sort of. I have like

class Appname.Model.User extends Backbone.Model
...

And it's sort of not that important actually. I really don't want to bother you with this stuff :) Maybe someone else could share his point of view on the matter.

And taking in account that as you said in Backbone it's not actually namespace in common definition I should just make my own fork or keep it the way it is. I think I'm going way too far in concern about naming things.

arboleya commented 11 years ago

I see, you many multi-level namespaces, so your better option now is to go on with search/replace for an immediate solution, and forget about capitalized namespaces.

I understand this kind of obsessive concerning about certain things, pay no mind. hehe

giuliandrimba commented 11 years ago

Hi @madundead , there is a difference between uppercase and lowercase namespaces, as Javascript is case-sensitive, a variable starting with lowercase is different than a variable with the same name but with uppercase. I usually make the namespaces with lowercase and the "Class Name/Object/Constructor Function" with uppercase.

Example:

app.views.Home = function(){} app.views.home.Gallery = function(){}

app.views.home is different than app.views.Home

Don't forget to create each part of the namespace as an object, so it wouldn't throw an "undefined" error.

I usually use this helper method to create namespaces: https://gist.github.com/4221198

So, I think letting the namespace and the Constructor Function with uppercase would not work, unless you use an Object instead of a Constructor Function.

I might be wrong, but in Backbone, there is just 1 level of namespace that is "Backbone", so its hard to have conflict between namespace and object/constructor function.

arboleya commented 11 years ago

@madundead @giuliandrimba Hi, just to let clear, the ns approach Giulian said doesn't apply if you're using Toaster, because Toaster do this ns things for you.

In other hand, when doing js "manually" it can be usefull, Toaster had a __t helper for it some versions ago: https://github.com/serpentem/coffee-toaster/blob/0.6.3/examples/single-folder/www/js/app.js

The pitfall of this method is that you may be unable to document your code properly, with some docs generator. It's because the dynamically created ns are harder to follow and sometimes it can't even be found (depending on the docs system).

So in the last versions of Toaster this helper was removed in favor of hardcoded declared objects: https://github.com/serpentem/coffee-toaster/blob/0.6.10/examples/single-folder/www/js/app.js

giuliandrimba commented 11 years ago

@arboleya @madundead Agreed with Arboleya, the approach Toaster use is better than creating namespaces at runtime.

arboleya commented 11 years ago

@madundead After some reflection, I see that in fact there's no viable use for this approach that can justify so much work implementing it. So I'm closing it.

Thanks for suggesting anyway.

madundead commented 11 years ago

Sorry it's been awhile.

@giuliandrimba Thanks, I get it now. @arboleya Thanks for your time.

Keep on hackin :thumbsup: