Qatrix
Qatrix copied to clipboard
global namespace clutter
Hey nice frame work.
I think it's a shame to clutter the namespace with so many $xxx
- it will cause collisions in some projects.
I'd consider changing it to be a single $ namespace, i.e. : $.id
rather than $id
- Global function is faster than namespaced function, because it do not have to query the namespace first and then call the function and will be better optimized for compilation on browser`s JavaScript engine: http://jsperf.com/global-function-vs-namespaced-function
- It will conflict with jQuery like
$.ajax
or others. - Easier to remember and shorter the function name.
- Better for search engine. Try search
$appned
,$prepend
,$ready
,$hide
on Google. On top right?
- The test was ±0.55% which is negligible
- You can use jQuery.ajax
- No easier to remember and - only 1 character shorter
- No better - try searching for $.append ...
On chrome, and firefox it is faster about 5-10%+
And yes, if someone want to know search the function document on Qatrix if use $.append
, Google will return the jQuery as top results. But now the top of results of $append
is Qatrix.
Ah, so the naming of functions is merely for SEO purposes, instead of for best practices. Makes sense.
The performance is the first target on Qatrix. So we choose global but namespace.
Trading a negligible amount of performance to violate best practices is not a valid argument.
Qatrix,
Your library is getting the attention of some very notable figures in the JavaScript community. This is your opportunity to shine, or go down in flames. Please listen to the criticisms carefully, and please, please do not write bad code just for the sake of getting ranked higher on a search engine for certain keywords. Write great code, and people won't have any problem finding you.
If your library pollutes the global namespace, potentially breaking other tools I may be using, you can expect to see the community react very negatively, and this will only hurt your progress.
You've been very fortunate to receive a response by the earlier commenters - take their sentiments to heart if you want to see Qatrix do well.
There are techniques you can use to get around the incompatibilities of jQuery or other libraries utilizing the $
namespace. For instance, you can cache the previous values, and return them to their previous owners by calling some sort of .noConflict
method:
(function (global) {
var Qatrix = function () {},
_$ = global.$;
global.$ = Qatrix;
Qatrix.noConflict = function () {
global.$ = _$;
};
})(window);
While $append
indeed is the top search result, only a fool would expect that to somehow garner users. I am not greatly concerned with the global functions (who is going to use this library with MooTools, causing the $each
collision, for instance?), rather, I find the $
everywhere to be onerous.
It is far better to define properties at Qatrix.each
, etc. for explicitness, and a code user may choose to alias these as necessary: If I am going to use $each
heavily in some loop where property lookup overhead could be a concern, I will of course var each = Qatrix.each
. Or for brevity throughout, I might var q = Qatrix
. This is to me far preferable to the noConflict()
clobber-by-default approach that jQuery has sadly popularized.
Of note is that this project's current SEO state is actually quite poor -- search for qatrix each
on Google and see that a YouTube channel is the top result even though qatrix
itself is dominated by this library.
Don't optimize to avoid property access in your library code! Compilers do this for you (var q=Qatrix,e=q.each ...
), and any project for which this sort of micro-optimization matters is almost certainly using a compiler already.
And great work on this library!
You should change it to this using $ or Quatrix , Qx etc
Qatrix
Qatrix.id
Qatrix.tag
Qatrix.class
Qatrix.dom
Qatrix.select
Qatrix.animate
Qatrix.fadein
Qatrix.fadeout
Qatrix.ajax
Qatrix.json.decode
Qatrix.json.decode
Qatrix.json.isJSON
Qatrix.url
Qatrix.style.get
Qatrix.style.set
Qatrix.css.get
Qatrix.css.set
Qatrix.show
Qatrix.hide
Qatrix.offset
Qatrix.pos
Qatrix.event.add
Qatrix.event.remove
Qatrix.event.key
Qatrix.event.metaKey
Qatrix.event.target
Qatrix.ready
Qatrix.className.add
Qatrix.className.set
Qatrix.className.has
Qatrix.className.remove
Qatrix.new
Qatrix.append
Qatrix.prepend
Qatrix.before
Qatrix.after
Qatrix.remove
Qatrix.empty
Qatrix.html
Qatrix.text
Qatrix.cookie.get
Qatrix.cookie.set
Qatrix.cookie.remove
Qatrix.string.camelCase
Qatrix.string.replace
Qatrix.string.trim
Qatrix.attr.get
Qatrix.attr.set
Qatrix.attr.remove
Qatrix.data.get
Qatrix.data.set
Qatrix.data.remove
Qatrix.cache.get
Qatrix.cache.set
Qatrix.cache.remove
Qatrix.cache.inc
Qatrix.cache.dec
Qatrix.cache.flush
Qatrix.each
Qatrix.clear
Qatrix.loadscript
Qatrix.rand
Qatrix.browser
Thank all. I will consider all suggestions and think around to make the change as possible.
But i really want to get to know the real user experience while using the framework in reality. How high the possibility of conflict will be encountered by this "namespace pollution" with inconvenient? Is it really common that to use two or three frameworks in a project at the same time and to name the variable or function name with $
as prefix?
@pigdude if the compiler will handle var q=Qatrix,e=q.each ...
, why the benchmark http://jsperf.com/global-function-vs-namespaced-function show that it will be slower?
@alejandrolechuga Although it can solve the namespace problem, it can not called "less code" anymore, right?
@qatrix, I don't think you understand what I mean. When code is passed through a compiler, only flat variables remain. the property o.p.q
becomes opq
.
The new version of Qatrix can use function under the namespace Qatrix
now.
And it can compatible working with jQuery with some techniques: http://qatrix.com/tutorial
What if another code is using this name "fn" in the global scope
for (var fn in Qatrix)
{
window[fn] = Qatrix[fn];
}
window.Qatrix = Qatrix;
@alejandrolechuga Load Qatrix framework at first. If have conflict problem, use those techniques: http://qatrix.com/tutorial
And actually in common, how high the possibility you will use $ as the prefix of common function name on your JavaScript code? If you keep that in mind, you will not encounter nothing conflict while using Qatrix.
global functions may be microseconds faster than namespaced functions, but whats more important? - maintenance, or micosecond difference in performance? Why is require.js populate? The reason is because it keeps your dom clean. What happens when a user creates a function that happens to rewrite an existing window function? You're screwed then.
@inspiraller
- The performance is the first goal of this framework and the global function is faster nearly 10%.
- If have conflict problem, just use those techniques: http://qatrix.com/tutorial