Live data from Hacker News

Maintainable JavaScript (2014)

alexkras.com

1–10 of 33 posts

Re: Maintainable JavaScript (2014)

#3

Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?

Yes and no. Ideally the main logic part should have none of the html-like part. Views should be dumb and do as little as possible.

Of course in practice ...

This is def a lot better than what I currently use in production: Handlebars hacked to the point of almost being JavaScript but not really. Then you both have views with too much logic and they're annoying to implement.

At least with React you get the full expressiveness of JS right in your views.

Re: Maintainable JavaScript (2014)

#4
post #3

Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?

Yes and no. Ideally the main logic part should have none of the html-like part. Views should be dumb and do as little as possible. Of course in practice ... This is def a lot better than what I currently use in production: Handlebars hacked to the point of almost being JavaScript but not really. Then you both have views with too much logic and they're annoying to implement. At least with React you get the full expres…

> Views should be dumb and do as little as possible.

Yes, just like React advocates.

Re: Maintainable JavaScript (2014)

#5
post #3

Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?

Yes and no. Ideally the main logic part should have none of the html-like part. Views should be dumb and do as little as possible. Of course in practice ... This is def a lot better than what I currently use in production: Handlebars hacked to the point of almost being JavaScript but not really. Then you both have views with too much logic and they're annoying to implement. At least with React you get the full expres…

I played around with a lot of different architectures for my React applications, and eventually ended up with something very close to traditional MVC, with components that are either view components, or controller components, but not both.

Re: Maintainable JavaScript (2014)

#6

Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?

Well it's well known that Facebook is familiar with PHP and I guess with the oldschool PHP mixing code and representation approach. So why not introduce that approach into the React then :)

Re: Maintainable JavaScript (2014)

#7
post #3

Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?

Yes and no. Ideally the main logic part should have none of the html-like part. Views should be dumb and do as little as possible. Of course in practice ... This is def a lot better than what I currently use in production: Handlebars hacked to the point of almost being JavaScript but not really. Then you both have views with too much logic and they're annoying to implement. At least with React you get the full expres…

I ditched handlebars because of that. I used dust and some twig implementation.

Re: Maintainable JavaScript (2014)

#8
post #5
post #3

Earlier quoted context omitted.

Yes and no. Ideally the main logic part should have none of the html-like part. Views should be dumb and do as little as possible. Of course in practice ... This is def a lot better than what I currently use in production: Handlebars hacked to the point of almost being JavaScript but not really. Then you both have views with too much logic and they're annoying to implement. At least with React you get the full expres…

I played around with a lot of different architectures for my React applications, and eventually ended up with something very close to traditional MVC, with components that are either view components, or controller components, but not both.

It's just about personal taste. MVC is fine, I've built quite a few apps with that approach. JSX is weird but I still find it a viable approach. #nosilverbullet :)

Re: Maintainable JavaScript (2014)

#9

Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?

Only if you're so ignorant of how React works that you don't realize the JSX isn't HTML, it's syntactic sugar/an alias for the React.createElement method.

It's no different than $(

) in jQuery, so unless you're referring to some pre 2007 attitude, what are you talking about?

Re: Maintainable JavaScript (2014)

#10
He uses the following example for when to throw your own errors:

  var Controller = {
    addClass: function(element, className) {
      if (!element) {
        throw new Error("addClass: 1st argument missing.");
      }
      element.className += " " + className;
    }
  };
I don't think this is a very good as a native error will have all this information already in a stacktrace, and if you're running Chrome dev tools with 'Pause on exceptions' then you'll be shown the exact place this fails. Additionally, you need to now keep the function name in sync with the string (your IDE / build tool will not tell you if they get out of sync).

Better cases for custom errors are situations where a native error will not be thrown, such as:

- in his example method: if className is undefined

- valid objects in a state you don't expect

- switch statements that don't match any expected case

- etc.

Post reply on HN