Web Browser Programming Blurring the Lines of MVC
lkcl tips his in-depth article up at Advogato on the difficulties for the MVC programming model that are introduced by Javascript and AJAX, and solutions for them. He writes: "This article outlines how the MVC concept is made incredibly awkward by the gradual but necessary introduction of Javascript and AJAX. A solution is found in the form of Javascript Compiler Technology such as GWT or Pyjamas (PyPy's JS backend or Rb2Js could be used, with some additional work). The article outlines how and why the traditional MVC patterns are fragmented by Javascript and AJAX, advocating that if a site is programmed purely in a high-level language that is then compiled to Javascript for the Web Browser sections, the same high-level source code can be executed either client-side on the browser, or server-side, or even both, depending on the requirements. The implications of this approach are discussed in depth."
also found, since the submission, rubyjs which is a ruby-to-javascript compiler and yet another port of GWT - this one's called rwt
The lines between what is an application are blurring. We have disparate data sources which are being combined in ways which the original sources never necessarily intended. The user application may or may not even be one written by the service provider.
The semantic web, despite all the nay saying, is here.
The internet, being a series of tubes, naturally adapts itself to the PVC, rather than MVC, model.
If you post it, they will read.
Call me jaded, old, and behind the times... But what ever happened to a web browser just being a web browser instead of a development platform with three heads breathing fire, half a dozen plugins, six months of combatability testing, and a kitchen sink? Is there ever a point where a web developer will concede that the web is not the Best Platform for Everything in The Universe(tm)? Or is it just that they were never schooled in the old temple and given a proper appreciation of a real language like C++? Help me out here -- this isn't intended as a flame but an honest question -- where does this attitude that everything has to be crowbar'd into a web interface to be considered modern these days? Because a lot of the problems in this article come down to programmers expanding and bloating their platform/language of choice to do something it was never designed for because That's Just What I Know(tm). :( I cry for these languages. I know after 5pm they go home and hit the frozen dairy products hard to feel better about how fat they've become.
#fuckbeta #iamslashdot #dicemustdie
"the same high-level source code can be executed either client-side on the browser, or server-side, or even both, depending on the requirements"
Careful when you blur the lines.
The gains might not be as much, because there's a very big difference between running your code on an untrusted client vs running your code on your server.
It may be rather hard to enforce the integrity and security checks at server side when you start to do more and more stuff on the client.
If the server has to counter check each step, then you still get that round trip latency effect. If you do most of the stuff client side that could mean the server has to figure out what are valid _end_ states from tons of possible intermediate states. Sometimes that might not be possible.
It's not a problem for things like google maps, if you modify their client side javascript to behave differently it's not a big issue.
... schooled in the old temple and given a proper appreciation of a real language like C++?
You're going to have to inform us "young'uns" of what is and isn't a "real language." You see, I can't even begin to help you until you concede that if a tool gets the job done, it's a good tool. It might not be the best tool but it's a good tool. Stop making inflammatory statements.
What you misunderstand about this change of direction is that microarchitectures and new hybrids of old design patterns are arising to meet the needs of web developers.
where does this attitude that everything has to be crowbar'd into a web interface to be considered modern these days?
If you write a C++ program and compile it down to one architecture, how many users do you have? If you write a browser, OS, architecture neutral application and make it available to everyone online, your user base skyrockets dramatically.
I cry for these languages.
And these languages cry for you and your closed mindedness towards new ideas. Java was a bad idea at first and yet somehow it has found a niche--more than a niche if you ask me.
I'll meet you half way, I agree C++ is far faster than anything I've been paid to code in. Now you come the other half of the way and maybe we'll have a discussion here where useful information is exchanged.
My work here is dung.
And if it doesn't float it's a witch?
After quickly skimming the article, it seems that the "problem" isn't so much with MVC itself as it is with people not understanding what it is. Apparently, a lot of web developers have thought that "model/controller = server-side, view = client-side". This is obviously wrong, and, of couse, JS and AJAX become extremely confusing to categorize in such a system. No surprise there. Also, article makes a big deal out of the "problem" that JavaScript can be used to work around the requirement that "server generates the view" - but of course, it was never a requirement of MVC, either, and indeed, the original MVC did not imply any sort of "generation" of the views.
Of course, the something-to-JS compilers that are so popular these days won't help, either. JS-the-language is good enough, replacing it with Java (or Python, or Ruby) on the client doesn't really help much, so long as the dividing line between the client and the server remains.
Yeah I'm pretty tired of people crapping on PHP and by extension those of us who use it (by choice or necessity).
Yes it has its problems (not the ones mentioned in the article which are either out of date (magic quotes) or PEBKAC (most of the rest), but there's nothing that major.
Like anything, use it improperly and you'll come out with crap.
Also to be honest there's no problem with AJAX and MVC, your Javascript should be making requests to your server-side controller(s) in the same way your generated HTML does (the only difference is your requests and responses are async in comparison to your regular HTML initiated GETs and POSTs). Any application logic in Javascript beyond interface manipulation just means you're doing it wrong.
There's always going to be some processing going on for the view layer (whether it's during HTML generation, or at 'run time' in the browser as JS).
HTML + JS suck for making applications, but not for the reasons in the article.
Incidentally if you're after an event driven widget framework for PHP then Prado looks interesting. Seems similar to Tapestry for Java. Far less restrictive than horrors like GWT. I've not used it myself though as I don't think it's really compatible with my homegrown MVC framework, so I can't vouch for it.
I have long argued that MVC doesn't even make sense on the web to begin with. MVC is a great architectural model for live interactive systems, but a web site or web app is not a live interactive system. It's an asynchronous challenge/response system.
I blame Sun for completely abusing the term in their Java stacks (I think they called it "model 2"?), and Ruby on Rails for popularizing the wrong impression. MVC by definition requires a direct observer connection from View to Model. All web-MVC frameworks I've seen start with the initial statement that the Controller, not the View, is responsible for handling user interaction and communicating with the Model. Sorry, that's not MVC. It's not a bad model for the web, but it's not MVC. If anything it's closer to PAC.
See the link above for a lengthier analysis and links to Wikipedia. :-)
Really, the whole point of design patterns is to have a common vocabulary. How is that useful if you're going to bastardize your terminology due to stubborn ignorance?
--GrouchoMarx
Card-carrying member of the EFF, FSF, and ACLU. Are you?
The problem is that I have yet to see an implementation through a browser that can challenge a native GUI implementation and yes this includes Sales Force, Google Mail, Google Docs and all the rest of them.
that's why i ported pyjamas to the desktop:
http://pyjs.org/
pyjamas-desktop basically rips out all of the javascript, and replaces every single javascript-based function with exact same corresponding functionality that manipulates the DOM model of the underlying technology.
and i chose http://webkit.org/ as the DOM-manipulating technology.
i _could_ have chosen XUL / Gecko, but it took so damn long to find Hulahop - http://wiki.laptop.org/go/HulaHop - that i had to go for webkit.
i could have chosen PyKDE / KHTMLPart but it has very subtle bugs that require the entire KDE library to be compiled with c++ RTTI switched on. if it's switched off, the whole thing falls over.
by porting pyjamas to the desktop, it's possible to make the same application run as EITHER a desktop application (and i don't mean "running as javascript under Adobe AIR") OR a web application.
same source code. unmodified.
it's very cool.
For every instance of MVC, the View component itself can be a complete, nested MVC unit or even a collection of MVC units. This is the nature of the MVC design pattern.
For example, take the humble HTML button. It is its own complete MVC machine. It has a Model (button state, color, size, etc) and controller logic that responds to events (render "down" state, "focus" state, etc.). And of course it has a graphical View.
This MVC button machine can delegate events and control to a parent MVC machine, such as an HTML table.
Delegation continues to parent MVCs at ever higher abstraction layers until finally we're at the level of browser-as-complete MVC machine. The next higher layer involves the server back end, and now the browser is the view component of the server/browser abstraction layer.
If the server implements its GUI interface layer as servlets, for example, then the servlet/browser is a complete MVC machine. But this layer still does not contain the core business logic, since for any well-designed (non-trival) server it should be possible to completely replace the GUI layer (such as Struts, etc) with another GUI framework without affecting the core business logic/data. And so the browser/servlet layer becomes the view component of the highest MVC layer, which has the core business logic as the model and controller.
The MVC pattern supports a recursive tree of MVC state machines, typically managed as parent-child relationships. Low level business logic, such as preventing alpha characters from being entered into a SSN text input field, can be implemented directly in the input field widget's MVC machine. High level business logic/data, such as validating and submitting a complex shopping order, takes place on the highest level MVC state machine.
Business logic/data, like any complex computer science problem, can consist of many different levels of abstraction. It is absurd to think that the business logic of a non-trivial business application can be neatly separated into just three components of a single MVC state machine existing at a single level of abstraction. And so I just don't get this idea of blurring, unless it is just one person's understanding of hierarchal abstraction layers that is blurred, which has nothing to do with a limitation of MVC.
The challenge is in how to create code on the browser that fully leverages the MVC pattern. If code is to be as well organized, refactorable, and maintainable on the browser side as it is on the server side, an MVC machine needs the full OOP paradigm for expression. That's why tools such as GWT have become so attractive. Tools as these make it practical and affordable to distribute all business logic, high and low, to the proper layer of abstraction -- be it at the widget level, tile level, page level, server level, system level, or enterprise level.
Which is fine for the most part but I think peoples lack of care over things like MVC, nicely written code, etc has really ruined the web.
I disagree. I've been using the web since the Mosaic days, and I must say - it's better than ever! You can find what you're looking for more quickly, the content is richer and there is more of it.
A particular design pattern is NOT a silver bullet. I've used M$ Ajax/.NET to develop some websites and applications, and I was very pleased. Sure, it could use improvement, but what cant? Using it was way better than try to do some of the things manually. If the application works well and the code is maintainable, you have succeeded. As long as you plan out your application properly before you start writing it, things will go smoothly down the road.
I've worked on a project with C code that dates back to the 80's. It's not OO and doesn't knowingly follow any strict design patterns, but guess what? It's easy to follow, well documented, and above all, it does it's job!
I will say it again: If the application works well and the code is maintainable, you have succeeded.
while you may be right about some aspects of the Middle English creole hypothesis, the Norman conquest of England certainly had a profound effect on the evolution of the English language. language is a social/cultural construct. subsequently, its evolution is inextricably tied to the social & cultural development of a region. after all, a diachronic analysis is meaningless without historic context.
the fact of the matter is, the Norman conquest was a vital chapter in the historic narrative of the British isles. i would be very surprised if 300-odd-years of Norman rule had no effect whatsoever on the development of modern English. i mean, the Normans basically supplanted the English ruling class, replacing the entire English nobility with new Anglo-Norman-speaking Norman nobility.
it's true that the (disproportionately large number of) French and Norman loanwords used in the English language were largely borrowed after 1400, by which time English had returned to use in government and in the king's court. and the grammatical changes in English followed a pattern shared by many other Germanic languages. but the Great Vowel Shift was almost certainly influenced by Norman occupation in some way or another.
it should be noted that this (1200-1600) was the time when the language of the aristocracy was gradually shifting from French to English. this likely changed the prestige accent of English by making it sound more French in style. another possibility is that due to England being at war with France throughout much of this period, the French-speaking nobility may have been more susceptible to hypercorrection in an attempt to change pronounciation to something sounding "more English."
in fact, the shift from French to English as the language of the aristocracy/ruling-class may have contributed more to the rapid changes undergone by the English language to form modern English than the period of Norman rule immediately after William's conquest of England. firstly, William and his successors up to, and including, the early Plantagenets, such as Angevin kings, were all absentee rulers for the most part. the administrative system William set up allowed he and his successors to rule from France by writ. similarly, the early Anglo-Norman barons were also largely absentee landowners, who consider France their true home, and spent the majority of their time in France.
so it would make sense that it wasn't until much later, after the Anglo-Norman nobility had begun assimilating and interacting directly with the native English population, that these transformations in the English language began to take place. this was also the time of the Great Plague, which drove mass migrations to the South East of England causing different dialects and accents to intermingle and modify each other in order to standardize pronounciation. the rise of the middle class in London and upward social mobility caused by the pandemic hitting the aristocracy could also have driven (or accelerated) social interactions between the Anglo-Norman aristocracy and the English masses.
php being knocked like a GOTO statement *sigh* the problem is not the language but how it's used.