Advertisement
Guest User

Untitled

a guest
Jan 6th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. Sorry, but I'm going to be very harsh.
  2.  
  3. I think you might have a problem here, for I completely fail to understand what this library does. It looks like a mishmash of some functionality you need for your website, packaged as a “library”. But a library is supposed to be an encapsulated piece of functionality—in your case, it looks very specific to your app—moreover, the abstractions look very much messed up.
  4.  
  5. I have literally no idea what this code does, no matter how long I look:
  6.  
  7. // get library elements for each module
  8. $P.getLibElements = function (lib_hold, lib_global) {
  9. var list;
  10.  
  11. // iterate through each module
  12. $A.someKey($R.Classes, function (val) {
  13. list = val[lib_hold];
  14. if (list) {
  15.  
  16. // iterate through the module's l_hold properties
  17. $A.someKey(list, function (val, key) {
  18. list[key] = lib_global(val);
  19. });
  20. }
  21. });
  22. };
  23.  
  24. // initialize each module by property
  25. $P.initByProperty = function (prop) {
  26.  
  27. // iterate through each module
  28. $A.someKey($R.Classes, function (val) {
  29.  
  30. // if the property exists execute it
  31. if (val[prop]) {
  32. val[prop]();
  33. }
  34. });
  35. };
  36.  
  37. This is very cryptic too:
  38.  
  39. // turn off ajax animation
  40. if (wait_animation) {
  41. wait_animation.style.opacity = 0;
  42. }
  43.  
  44. // if the server want to talk it will prefix its message with |D|, and continue
  45. // normal comms with an |A|
  46. if (pass_prefix === '|D|') {
  47. message = pipe_string_receive.match(/^(\|D\|)([\s\S]*)(\|A\|)/);
  48. $A.log('|D|FROM SERVER|');
  49. $A.log(message[2]);
  50.  
  51. // remove the debug message
  52. pipe_string_receive = pipe_string_receive.slice((message[1] + message[2]).length);
  53.  
  54. // this should always be an |A|, update
  55. pass_prefix = pipe_string_receive.slice(0, 3);
  56. }
  57. if (pass_prefix === '|A|') {
  58. $R.time('middle');
  59. pipe = JSON.parse(pipe_string_receive.slice(3));
  60.  
  61. // if post exists run it
  62. if ($R.Classes[pipe.model].hasOwnProperty("post")) {
  63. pipe = $R.Classes[pipe.model].post(pipe);
  64.  
  65. // record timing information for pre(), transit, and post()
  66. times = $R.time('finish');
  67. pipe.time.pre = times[0];
  68. pipe.time.transit = times[1];
  69. pipe.time.post = times[2];
  70. $A.Reg.set('pipe_post', pipe);
  71. } else {
  72. return;
  73. }
  74. } else {
  75. throw "<No '|A|' or '|D|'>" + pipe_string_receive;
  76. }
  77.  
  78.  
  79. Or this:
  80.  
  81. $P.definePipe = function (obj) {
  82. $R.packet_hold = obj;
  83. };
  84.  
  85. So simple, yet I have no idea why assigning some object to a property called `packet_hold` in “private namespace” somehow makes this object a pipe.
  86.  
  87. The comments don't help because apparently **they were written for someone who already understands the system**. That's an unfortunate assumption to make.
  88.  
  89.  
  90. So it is both
  91.  
  92. * a poor man's JS OOP emulation layer (do you really need another one?);
  93. * a poor man's `require.js`;
  94. * some kind of state machine;
  95. * some kind of piping;
  96. * using AJAX and doing something with UI and animation?
  97.  
  98. The usage example doesn't clarify it one little bit:
  99.  
  100. S: {
  101. Arcmarks: new Arcmarks()
  102. },
  103. E: {
  104. fm: '#fm'
  105. },
  106. J: {
  107. fm: '#fm'
  108. },
  109. init: function () {
  110. $A.machine({model: this.Name});
  111. },
  112. initJ: function () {
  113. var self = this;
  114. $A.Event.add('malleable', function () {
  115. self.J.fm.draggable();
  116. self.J.fm.draggable('enable');
  117. });
  118. $A.Event.add('malleable_not', function () {
  119. self.J.fm.draggable('disable');
  120. self.J.fm.draggable('destroy');
  121. });
  122. },
  123.  
  124.  
  125. Your methods are mostly simple and nice, but unless you're writing a web app different from 99,9% web apps out there, you seem to have chosen wrong abstractions and bad naming.
  126.  
  127. **This is a rather unusual problem: your methods *seem* so simple I feel like I'm missing something, but I've re-read code several times, and I just don't get it.**
  128.  
  129. I encourage you to try to look at the code from a new team member's perspective. Do you really understand what's going on? The problem is exemplified by the fact that it depends on other modules with just as unfortunate method naming, like `someKey`.
  130.  
  131. I'm sure all great programmers go through this stage, [described by Joel](http://www.joelonsoftware.com/articles/fog0000000018.html):
  132.  
  133. >When great thinkers think about problems, they start to see patterns. They look at the problem of people sending each other word-processor files, and then they look at the problem of people sending each other spreadsheets, and they realize that there's a general pattern: sending files. That's one level of abstraction already. Then they go up one more level: people *send* files, but web browsers also *“send”* requests for web pages. And when you think about it, calling a method on an object is like sending a message to an object! It's the same thing again! Those are all *sending* operations, so our clever thinker invents a new, higher, broader abstraction called *messaging*, but now it's getting *really* vague and nobody really knows what they're talking about any more. Blah.
  134.  
  135. >When you go too far up, abstraction-wise, you run out of oxygen. Sometimes smart thinkers just don't know when to stop, and they create these absurd, all-encompassing, high-level pictures of the universe that are all good and fine, but don't actually mean anything at all.
  136.  
  137.  
  138.  
  139. Your code seems to suffer from architecture austronautry.
  140.  
  141. All great programmers have been there—the “a-ha” moment comes when you revisit such “smart” code months later and have no idea how it worked, how to fix, extend or explain it to somebody else.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement