Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38026 > unrolled thread
| Started by | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| First post | 2020-01-10 13:20 -0800 |
| Last post | 2020-01-12 15:04 +0000 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.lang.javascript
An example of an MVC architecture Julio Di Egidio <julio@diegidio.name> - 2020-01-10 13:20 -0800
Re: An example of an MVC architecture "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-10 13:53 -0800
Re: An example of an MVC architecture John G Harris <niam@jghnorth.org.uk.invalid> - 2020-01-11 15:02 +0000
Re: An example of an MVC architecture "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-11 11:05 -0800
Re: An example of an MVC architecture Julio Di Egidio <julio@diegidio.name> - 2020-01-11 23:53 -0800
Re: An example of an MVC architecture John G Harris <niam@jghnorth.org.uk.invalid> - 2020-01-12 11:33 +0000
Re: An example of an MVC architecture Julio Di Egidio <julio@diegidio.name> - 2020-01-11 23:51 -0800
Re: An example of an MVC architecture John G Harris <niam@jghnorth.org.uk.invalid> - 2020-01-12 14:53 +0000
Re: An example of an MVC architecture John G Harris <niam@jghnorth.org.uk.invalid> - 2020-01-12 15:04 +0000
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-01-10 13:20 -0800 |
| Subject | An example of an MVC architecture |
| Message-ID | <323d2bbb-3885-429f-91c7-cc028e4f16e3@googlegroups.com> |
Hi everybody, Those who might be interested in seeing a (simple) example of an MVC architecture in a web based app, please have a look at the "Inertial Frames" one here: <https://github.com/jp-diegidio/STUDY.Physics.SpecialRelativity> I also make extensive use of observables and two-way bindings (powered by Knockout.js), which I think are a necessary ingredient for dealing with complex interfaces. Not that this one is particularly complex, in fact the app and the code itself are pretty simple. But indeed the point of interest is the overall architecture, and that, I think, in its minimality, shows all the essential ingredients, at their place and with their interactions, modulo of course possible (but I'd expect, minor) variations. The code itself is not "optimal" in more than one place, but I propose this is also an example of real code, which is always work in progress: and what that means. Anyway, that much for a presentation. I just hope some might find it interesting. Feel free to ask questions, suggest improvements, report problems, etc. (in fact, it is an open project!). I am also open to discussing architectural issues, after all that is the main topic here, but only as long as it is remains a technical discussion... Enjoy, Julio
[toc] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-01-10 13:53 -0800 |
| Message-ID | <cbd06517-0a41-49f0-a3a5-aee50102642f@googlegroups.com> |
| In reply to | #38026 |
On Friday, January 10, 2020 at 3:20:52 PM UTC-6, Julio Di Egidio wrote:
> Hi everybody,
>
> Those who might be interested in seeing a (simple) example
> of an MVC architecture in a web based app, please have a
> look at the "Inertial Frames" one here:
>
> <https://github.com/jp-diegidio/STUDY.Physics.SpecialRelativity>
>
> I also make extensive use of observables and two-way
> bindings (powered by Knockout.js), which I think are a
> necessary ingredient for dealing with complex interfaces.
>
> Not that this one is particularly complex, in fact the
> app and the code itself are pretty simple. But indeed
> the point of interest is the overall architecture, and
> that, I think, in its minimality, shows all the essential
> ingredients, at their place and with their interactions,
> modulo of course possible (but I'd expect, minor)
> variations.
>
> The code itself is not "optimal" in more than one place,
> but I propose this is also an example of real code, which
> is always work in progress: and what that means.
>
> Anyway, that much for a presentation. I just hope some
> might find it interesting. Feel free to ask questions,
> suggest improvements, report problems, etc. (in fact, it
> is an open project!). I am also open to discussing
> architectural issues, after all that is the main topic
> here, but only as long as it is remains a technical
> discussion...
>
> Enjoy,
>
> Julio
I'm glad to see some real content on the group again after a bit of a dry spell. Below is only 5 mins of looking. I'll try to carve out some more time and clone locally to get a better look.
With this being an example; why not use the latest standard JavaScript and it's features such as modules?
Secondly, why do you define functions inside the constructor instead of on the prototype?
Wouldn't classes give your code more brevity? Snippet from:
<https://github.com/jp-diegidio/STUDY.Physics.SpecialRelativity/blob/master/InertialFrames/App/scripts/logic/sr.inertial.js>
```javascript
...
function Calc() {
...
var self = this;
...
this.setSpeed = function (b) {
...
self.frameB.grid._onSpeed();
...
}
...
}
```
Can you show reduced example why Knockout.js was
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-01-11 15:02 +0000 |
| Message-ID | <npoj1fpg9c16jtskkevr6sk8oc7bgtc0kn@4ax.com> |
| In reply to | #38027 |
On Fri, 10 Jan 2020 13:53:40 -0800 (PST), "Michael Haufe (TNO)" <tno@thenewobjective.com> wrote: <snip> >Secondly, why do you define functions inside the constructor instead of on the prototype? >Wouldn't classes give your code more brevity? <snip> Someone who says OO is wrong is unlikely to implement classes, and even more unlikely to use the 'class' keyword. Nor are they are likely to use ECMAScript's facilities for inheritance. My own comment is that his code is unmaintainable. Who knows what Calc's job is? Who knows if MOD is allowed to return the value m? John
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2020-01-11 11:05 -0800 |
| Message-ID | <f497c002-909c-4f3e-b917-24a0848ddde7@googlegroups.com> |
| In reply to | #38029 |
On Saturday, January 11, 2020 at 9:02:58 AM UTC-6, John G Harris wrote: > Someone who says OO is wrong is unlikely to implement classes, and > even more unlikely to use the 'class' keyword. > > Nor are they are likely to use ECMAScript's facilities for > inheritance. Which is also fine if a functional style was used instead of partly both. There are examples in Haskell [1] and Standard ML [2]. It could be an interesting exercise to do this in JavaScript functionally. [1] - http://www.haskellforall.com/2014/04/model-view-controller-haskell-style.html [2] - https://www.ccs.neu.edu/home/wand/etc/Stoughton-MVC-in-SML.pdf
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-01-11 23:53 -0800 |
| Message-ID | <9d6d2c1f-6a19-4600-9f69-4e9efc61a61c@googlegroups.com> |
| In reply to | #38029 |
On Saturday, 11 January 2020 16:02:58 UTC+1, John G Harris wrote: > Someone who says OO is wrong Will you keep lying about that till the end of time? *Troll alert* Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-01-12 11:33 +0000 |
| Message-ID | <hq0m1ft781f306tl6jmlp23dr7fnvbu83k@4ax.com> |
| In reply to | #38036 |
On Sat, 11 Jan 2020 23:53:10 -0800 (PST), Julio Di Egidio <julio@diegidio.name> wrote: >On Saturday, 11 January 2020 16:02:58 UTC+1, John G Harris wrote: > >> Someone who says OO is wrong > >Will you keep lying about that till the end of time? > >*Troll alert* Says the man who wrote "For the chronicle, OOP uber alles is a plain fraud" though he did amend that to "I meant the infamous OO uber alles, which of course is about the whole paradigm, not about this or that particular construct" John
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2020-01-11 23:51 -0800 |
| Message-ID | <eda1c138-79ee-4a49-9226-ba869cf5a18e@googlegroups.com> |
| In reply to | #38027 |
On Friday, 10 January 2020 22:53:46 UTC+1, Michael Haufe (TNO) wrote:
> With this being an example; why not use the latest standard JavaScript and
> it's features such as modules?
It is an example of an MVC architecture, so the specific JS I am using is
not really relevant. That said, I will be picking up new language features
along with browsers implementing them consistently, those that I like (I
do already use more advanced features under Node.js, but it's async/await
and little more). Why still stick to browser level and not just embrace
the babelisers, in short, is because I am an expert programmer and I do
write my own code, with a level of control and consistency that a non-expert
just cannot even guess, no scorn meant. (But mind you, I do use whatever
I am constrained to use on the job and without complaints: again, there is
more to programming than just programming, and these details are just not
that relevant in the big scheme of things production...)
> Secondly, why do you define functions inside the constructor instead of on
> the prototype?
Privileged methods are the best way to go with "big, structural" objects:
indeed usually these are "singletons": best because one gets information
hiding (private variables) more naturally, and usually the code is overall
a bit simpler/more straightforward (of the reasons I can remember from the
top of my head: these are best practices). I think there is only one object
in the whole code base where I should have done with methods in the prototype,
because it's a "small" one with many instances created, in fact it even
happens to have the semantics of a "value" type, and that is the Value
object in that sr.inertial.js. I will change that: thanks for mentioning
the issue.
> Wouldn't classes give your code more brevity?
Brevity? Besides that I hardly think so and even less brevity is
a principle, "classes", as you should know, I believe are completely
the wrong abstraction as far as JS is concerned. So, your mileage
may very well vary, but I just won't use them.
> Snippet from:
>
> <https://github.com/jp-diegidio/STUDY.Physics.SpecialRelativity/blob/master/InertialFrames/App/scripts/logic/sr.inertial.js>
>
> ```javascript
> ...
> function Calc() {
> ...
>
> var self = this;
> ...
> this.setSpeed = function (b) {
> ...
> self.frameB.grid._onSpeed();
> ...
> }
> ...
> }
> ```
> Can you show reduced example why Knockout.js was
Not sure what you were asking there: KO is heavily used, just not
in that file. Maybe I will post later few lines on the overall
architecture, what is what and where, for everybody's benefit.
That said, that file is indeed the least "elegant" of the lot
(but also the most irrelevant to the MVC part!), but I am not sure
how to improve on it, the performance considerations also taken
into account (a naive, purely functional approach just wouldn't be
efficient enough: as far as I can envision it). It would be cool
if you tried and rewrote it using the "object-oriented" constructs
and/or whatever functional you like...
Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-01-12 14:53 +0000 |
| Message-ID | <qfcm1f90nar606vcu5f3lv39b6oa5u32sn@4ax.com> |
| In reply to | #38035 |
On Sat, 11 Jan 2020 23:51:29 -0800 (PST), Julio Di Egidio <julio@diegidio.name> wrote: >On Friday, 10 January 2020 22:53:46 UTC+1, Michael Haufe (TNO) wrote: <snip> >> Wouldn't classes give your code more brevity? > >Brevity? Besides that I hardly think so and even less brevity is >a principle, "classes", as you should know, I believe are completely >the wrong abstraction as far as JS is concerned. So, your mileage >may very well vary, but I just won't use them. <snip> You say that, yet you've implemented a class, Value, but being an expert programmer you've written the code yourself instead of asking the compiler to write it for you. John
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2020-01-12 15:04 +0000 |
| Message-ID | <vadm1f9jck372t576r7p9t1dh5jgt41u1v@4ax.com> |
| In reply to | #38026 |
On Fri, 10 Jan 2020 13:20:45 -0800 (PST), Julio Di Egidio <julio@diegidio.name> wrote: >Hi everybody, > <snip> >Anyway, that much for a presentation. I just hope some >might find it interesting. Feel free to ask questions, >suggest improvements, report problems, etc. (in fact, it >is an open project!). I am also open to discussing >architectural issues, after all that is the main topic >here, but only as long as it is remains a technical >discussion... It'd not clear why there are separate Model and Logic components. I thought Model was the name of the part containing the data structures along with the code that knows how to manipulate that data. John
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web