Jan. 7th, 2016
MVC, no big deal
Jan. 7th, 2016 11:39 amI was pondering, how does MVC map onto modern paradigms. Say, we abstract from State Monad, from ScalaZ State Monad, just look into it as if.
Easy.
Controller calls Model, passing a callback to View, that's it.
So model gets the data and calls the view, that's it.
We don't have to figure out in controller, what was it, and then call view or whatever.
Also, we can parallelize it heavily.
Like in JavaScript, like in AJAX (async version).
It's pretty much a state machine, right? Controller is input, Model is State (monad), View is output.
I know, I know, it's all trivial, kind of.
But so many times we write code that calls something and waits for results and then processes (e.g. visualizes) the results... I'm starting to figure out that it's not beautiful. I mean, at times it is, but frequently it's not.
Alternatively, we can pass two functions, one "onsuccess", another one "onerror". Same as a function on a union, right? Categorically speaking.
Easy.
Controller calls Model, passing a callback to View, that's it.
Controller.iWantSomething() { Model.giveMeSomething(args, myView:Something => ()) }
So model gets the data and calls the view, that's it.
We don't have to figure out in controller, what was it, and then call view or whatever.
Also, we can parallelize it heavily.
Like in JavaScript, like in AJAX (async version).
It's pretty much a state machine, right? Controller is input, Model is State (monad), View is output.
I know, I know, it's all trivial, kind of.
But so many times we write code that calls something and waits for results and then processes (e.g. visualizes) the results... I'm starting to figure out that it's not beautiful. I mean, at times it is, but frequently it's not.
Alternatively, we can pass two functions, one "onsuccess", another one "onerror". Same as a function on a union, right? Categorically speaking.
что я писал в дневнике ровно 25 лет назад
Jan. 7th, 2016 09:08 pm"Хлопоты! Началась перестройка на кухне! Старые вещи - вон!"
(А вот что перепечатывал 10 лет назад: "Почему на Майдане было так много людей, почему они все туда вышли? Потому что большинство из них прошло через издевательства — налоговые, над бизнесом, плату государственному рэкету, физические расправы, запугивание перед выборами и т.д. и т.п. Каждый второй там был жертвой этого режима.")
(А вот что перепечатывал 10 лет назад: "Почему на Майдане было так много людей, почему они все туда вышли? Потому что большинство из них прошло через издевательства — налоговые, над бизнесом, плату государственному рэкету, физические расправы, запугивание перед выборами и т.д. и т.п. Каждый второй там был жертвой этого режима.")