On 06/17/2014 02:15 PM, Torstein Saltvedt wrote:
But here you place the entire logic and presentation of the application in a single 150 lines of code long function.

It reminds me about the awful SQL/HTML spaghetti I wrote when I first started learning programming with PHP. And while the Ur/Web code is probably totally fine with all it's fancy type-checking and whatnot, it looks /really/ /scary/ to my object oriented eyes.

IMO, this example needs so little code that splitting it into components in separate files could actually impede maintainability.

As an experiment, I've put up a version, at the same URL <http://www.impredicative.com/ur/todomvc/>, splitting the HTML styling into a separate module. What do you think?

What about keeping code DRY?

Where in particular are you seeing undesirable repetition?

Separation of concerns?

This one is too broad for me to comment on.

Preventing too many levels of nesting?

That's in the eye of the beholder, I guess!

Keeping functions short and testable?

I don't generally think of this criterion as too important in languages with expressive static type systems. I don't do systematic testing, and I feel like most such testing in Ruby, etc. is just finding type errors! (Keep in mind that type systems can capture much stronger properties than in mainstream languages, such as Ur/Web's use of types to catch bad links, schema-incorrect database accesses, the equivalents of "wrong ID errors" in imperative JavaScript code, etc.)

Encapsulation?

Ur/Web's encapsulation facilities are IMO far superior to those in Ruby on Rails, with the possibility for module-local database tables, encapsulated GUI widgets whose private state can't be messed with even by other Ur/Web code that contains deliberate mistakes, etc. This example is just too small to call for serious use of module structure.

If you wanted to change the TodoMVC implementations of the mainstream javascript frameworks to use persistence you would only need to change the models. The rest of the application would stay the same. (Let's just ignore the actual REST API.)

I know it is asking a lot, but I would love to see how this would be refactored to use Ur/Webs database persistence.

Done, as another part of the same demo-set. The todo list is written to the remote database every 5 seconds, and refreshing the page starts from the current database contents. I started from the version with a separate module for HTML styling, and the diff is under 30 lines of code, including a small extraction of a reusable function that might also make sense for the original version.
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to