johnsoncheng / .plan

2 stars 1 forks source link

Suitability of Javascript #1

Open middric opened 10 years ago

middric commented 10 years ago

If we are to move to a client side architecture I think we should re-examine our use of javascript and php.

We are already at a point were the javascript code is approaching unmaintainable levels and I'm starting to think no amount of MFM/jQuery/angular/whatever is going to solve the problem of writing structured code in an unstructured language.

I suggest we start looking at alternatives:

All of these can be run server side and I think we'd be crazy not to use the same language on both front and back... maybe between apps too? Would be fantastic if iBL and responsive both used the same language.

I've started writing some Dart and its very nice - I plan to write the same code in all 4 so I can compare.

*Ticked languages show those I've written code in.

johnsoncheng commented 10 years ago

Interesting. What about frameworks like Knockout, where you hide a lot of that complexity behind the data binding? Oh I guess you said Angular wouldn't be good enough either... Which part of our JS codebase do you think is the most unmaintainable? And would we be able to see why, and how a more "structured" language would solve those specific problems?

Would be really cool to see your comparisons :)

middric commented 10 years ago

I think the problem is javascript itself. Any javascript work that reaches a certain scale starts to become a mess of callbacks, async hell and hacked code. This is the nature of a language that allows you free reign over types and structure. Tools like require and angular etc help but they rely on the developer using them correctly and not using the loose structure of javascript so that they can work around parts of the framework they dislike.

Using a structured, typed language enforces a tighter api, a class based approach, and more test driven code.

johnsoncheng commented 10 years ago

Ah yeah I see what you mean. I find in general forcing yourself to never use anonymous functions make things at least cleaner to look at (http://callbackhell.com/), but I guess the stylistic rules would need to be enforced during the build since it's not part of the language.

middric commented 10 years ago

Dart code: https://github.com/middric/scripting-languages (most relevant file: https://github.com/middric/scripting-languages/blob/master/lib/carousel.dart)

I've omitted the html from the repo as it mirrors the new iplayer homepage. But you should get an idea of the code. It paginates the carousel left and right + some unit tests.

Next typescript!