MVC?

Started by Tyrsson, May 22, 2022, 11:51:45 PM

Previous topic - Next topic

Tyrsson

PM at your own risk, some I answer, if they are interesting, some I ignore.


Tyrsson

Quote from: Oldiesmann on May 23, 2022, 02:41:17 PM
Quote from: Joey Smith™ on May 22, 2022, 11:51:45 PMMVC?

https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
@Oldiesmann Thats what I figured lol, and have built several applications using the MVC architecture but it confused me here because smf is far from MVC so I was not sure if that is what @rcane was referring too...
PM at your own risk, some I answer, if they are interesting, some I ignore.

Arantor

Quote from: Joey Smith™ on May 23, 2022, 03:28:01 PMsmf is far from MVC

Only in places; index.php is vaguely an IoC style router, the functions called directly are controllers, models absolutely exist (e.g. createPost, registerMember, deleteMembers), and the templates are all presentational logic not business logic making them views.

Tyrsson

Quote from: Arantor on May 23, 2022, 03:29:27 PM
Quote from: Joey Smith™ on May 23, 2022, 03:28:01 PMsmf is far from MVC

Only in places; index.php is vaguely an IoC style router, the functions called directly are controllers, models absolutely exist (e.g. createPost, registerMember, deleteMembers), and the templates are all presentational logic not business logic making them views.
Its a stretch. I have recently been thinking along the same lines in regards to how to best break up SMF in those terms. Since I have started the process of attempting a loose translation to Laminas (just as a personal learning experience and I really do not look to finish it, just to really get a feel for what it would take).

I disagree that a file with a bunch of functions truly represents a Model in the spirit of MVC. Yes its a collection of related logic but beyond that...

It just comes down to opinion, and yours is certainly valid, because honestly. In a procedural application, its really as close as you could get.

True, the template files are 100% view.

And true, index.php and its smf_main() and use of the $actionArray is more or less a router of sorts.

I also disagree that a single function can truly represent a controller entity. I suppose that in its most simplistic implementation I suppose it serves, but it should really be able to represent more than a single action. and I suppose they could depending on the arguments etc that are passed or based on the action array and the request (querystring params) etc etc, but, to me at least it seems a stretch.
PM at your own risk, some I answer, if they are interesting, some I ignore.

Arantor

Quote from: Joey Smith™ on May 23, 2022, 04:06:46 PMI also disagree that a single function can truly represent a controller entity.

I wasn't suggesting that it was. I was suggesting that it represents a controller route, just as it would in Laminas; you have one route corresponding to a controller method that represents the actions taken in that route.

The only difference is that the actions are grouped as collections of functions rather than in classes, and the only reason that *matters* is if you plan on managing state by way of injecting parameters in a la dependency injection. Since DI was not a common pattern in PHP in 2004 - and for the most part in PHP applicatoins just tends to generate boilerplate rather than something useful - it makes sense that SMF does not largely bother. (There are surprisingly fewer cases for doing DI than it being 'good principle', because in practice most applications do not write multiple adapters or swap them out for different implementations, not even mocking purposes. That tends to be the province of the libraries and the frameworks who realistically care.)

Nothing says models have to be single classes that map 1:1 to database tables (the way Laravel etc. do), and you can map any combination of classes or methods to routes in Laminas (or any other framework) and munging everything into one god class or grouping things by route segments, or even one class per route, they're all valid approaches.

Tyrsson

Quote from: Arantor on May 23, 2022, 04:42:49 PMI was suggesting that it represents a controller route
That I agree with.

@Arantor, I, agree with most of what you said. Like I said, when it was written, and in a procedural arch, I really have a hard time trying to think of a closer approach than what SMF provides.

Quote from: Arantor on May 23, 2022, 04:42:49 PMmunging everything into one god class
I have to disagree with this. IMHO that is NEVER a valid approach except maybe for the most simplistic use cases.

And, honestly. As you stated, when SMF was written and the bulk of its code newly developed most of what we are currently discussing did not even formally exist then in regards to established patterns and arch in the Php world, trust me, I understand this. But that also, tends to supplement two points. 1). We can see the why and how of the birth of several of the patterns and arch we are discussing within SMF. 2). Its hard to make a case for an application fitting a pattern / arch that really didnt exist when it was planned and developed. Are there many similarities? Most certainly and we can see how the development of SMF and other applications like it has driven Php and web architecture in general. I mean lets face it, reading code from SMF in its current state is like looking back in time in regards to web application development in many ways. Is it still valid, sure. Does it still work? Sure. But its far behind the norm these days.

Im really not trying to debate all these points. Like I said, its just my opinion and as they say, every body as one lol. I dont have to be right. Matter of fact, youre probably more right than I am, and that's ok. Doesnt mean Im gonna change my mind ;)
 
PM at your own risk, some I answer, if they are interesting, some I ignore.

Tyrsson

PM at your own risk, some I answer, if they are interesting, some I ignore.

Arantor

Thing is, MVC was presented in an OOP context back in 1988 or so for Smalltalk; it's not like it was a new idea when SMF adopted it as a light-touch approach, though it was somewhat rare to have a front-controller approach in PHP apps in 2004 - see how phpBB and MyBB *still* don't do this generally, but direct users to dedicated PHP files for some tasks.

Here's the more controversial take: is it a *good* thing that the current approaches have been adopted as pushed for by Laminas etc? My answer is a very nuanced... well, actually... I'm not sure.

SMF can still handle more requests per second than Laravel out of the box. The bootstrap process is cheaper, the memory use much lower. SMF 2.1 frequently consumes under 1MB of RAM to render the page, even going as high as maybe 4MB to render some chunkier pages. And it's blazing fast.

Laravel cannot actually match that, definitely not Symfony either. Are they quicker to program? Arguably. They *are* kinder to start out from scratch because half the app is built for you, but as I've proven it's possible to take an SMF, hack off the forum and build something else that'll do the job in a few hours because routing, authentication etc. all present and correct.

And suddenly you find all the question marks about architectural purity and technique need to be reviewed because in context, the ideology does not hold up as well as you'd think. It's why XenForo didn't build themselves directly on top of Laminas or ZF (even if they use components from it), because they need the performance that you can only get by *not* doing that.

I sometimes think in chasing ideological purity we forget what is actually important.

Tyrsson

Quote from: Arantor on May 23, 2022, 05:23:45 PMThing is, MVC was presented in an OOP context back in 1988
Not in php it wasnt lol. But I understand what you mean, but I was referring to the world of Php in particular.

Quote from: Arantor on May 23, 2022, 05:23:45 PMSMF can still handle more requests per second than Laravel out of the box. The bootstrap process is cheaper, the memory use much lower. SMF 2.1 frequently consumes under 1MB of RAM to render the page, even going as high as maybe 4MB to render some chunkier pages. And it's blazing fast.
Now true, using Laminas for example, the memory usage would be alittle higher, and the application I am currently building is nowhere near as complex as SMF, however, I have a CMS running that has sub-second (0.22 - 0.4 but ive not really tried to optimize alot) page loads and that is with no caching implemented to date. With about 10-12 queries depending on the area of the application.

You're not telling me anything I dont already know. Yes, I know XenForo didnt use it out of the box. Very few projects would have back then as that project started when ZF was still in the 1.x version if memory serves, might have been 2.x but I dont think so. Much of this come down to personal preference as far as this pattern or that.

Which is also why Laminas built Mezzio, micro framework, which I just have not made the switch too because of the learning curve. I had enough to tackle just getting back up to speed on the Php language advances. Now that I'm getting my legs back under me I may have to setup a Mezzio test or two.



 

 
 
PM at your own risk, some I answer, if they are interesting, some I ignore.

Advertisement: