handmade.network » Forums » Developing the Web in a different language
tienery
Luke
7 posts
#15236 Developing the Web in a different language
6 months ago Edited by Luke on May 12, 2018, 10:34 p.m. Reason: Initial post

There are multiple languages out there that, in my opinion, suffer the same burdens as PHP with server-side web development, and do not resolve some of the core problems PHP has, such as forcing people to use a specific web design philosophy (MVC). I think web development should not be purely about MVC, and the arguments against using MVC are very similar to the arguments against OOP. That's not to say that certain aspects of MVC are bad, but it is understood that interconnecting models to connectors, connectors to views, and views to connectors, is complex and adds unnecessary hierarchical coding structures that can be better organised simply by having different files built for specific pages on your website.

Now, I must confess I am not an expert in any given programming language, and I am not in the position to say whether or not Web development should be developed in X way or Y way. But I think it is commonly accepted that the Web is poorly designed and has been constructed off the back of OOP, and uses event-based programming in the form of `addEventListener` which promotes excessive use of callbacks. You can't escape this unfortunately, and that is especially true for websites heavily animated like the one I am designing.

I wanted to avoid using JavaScript and PHP altogether, but not have to learn multiple other languages to design a clean, smooth-running website.

I have been using a programming language called Haxe, which is an open source language with a standard library and cross-platform toolkit, including its own compiler. It builds your Haxe code as if it were the solution, then generates code for the target language of your choosing, whether that is JavaScript, PHP, C#, Java, C++, Lua, among others. Haxe-generated JavaScript is roughly 33% faster than hand-written JavaScript, unless you code in the exact same style as Haxe-generated JavaScript, of course.

Generally speaking, Haxe's compiler is actually quite fast.

Endorsing aside, then, I have come really to show you how we might be able to program a better Web. Using Haxe, you can ultimately use one code-base for both JavaScript and PHP, the only things you need to change is whether your connecting to a database and how you handle such requests. Data structures and data-handling can be left untouched once in place.

Now, I say "program a better Web", we would still technically be using PHP and JavaScript, but Haxe does a decent job at generating code that performs solidly in both these areas. PHP could do with a bit of work, though. What this means, however, is that we don't have to look at cumbersome code and we can instead look at purely Haxe code. Since Haxe is strictly-typed and it compiles, you can catch most errors before they reach your website.

I have decided to start a tutorial series which encapsulates much of this by using a router (no OOP involved), and using AJAX to make server requests to get back text data that is easily decoded and parsed on-screen in their respective places. I'm not sure if it's in the spirit of Handmade, but the idea is to use a minimal number of libraries possible.

The only library I would use is Markdown for blogging and content-focused web pages, but everything else would be tied to the Haxe standard library.

You can see my YouTube videos here.

What do you think? Is this the kind of philosophy we should strive for with regards to Web development, or is this perhaps not far enough? I would appreciate your feedback, opinions and views on the subject.
mmozeiko
Mārtiņš Možeiko
1824 posts / 1 project
#15238 Developing the Web in a different language
6 months ago

Which server-side web development language forces to use MVC? I have done some web development in different languages (Delphi, C++, C#, PHP, Python) and I never used MVC. If you talk frameworks, then that is different story. But nobody forces you to use frameworks, just write code that does the things you need and it'll work with pretty much any language.
tienery
Luke
7 posts
#15242 Developing the Web in a different language
6 months ago

Perhaps I should not have written it that way, or written it at all. I must admit, I failed to proofread and edit properly before submitting. I was perhaps talking about frameworks. A lot of academics in my knowledge and experience teaches you to work with certain frameworks, like Wordpress or Joomla!, or follow that pattern of object-oriented programming without exploring solutions outside of that curriculum, and mixed it up with my bias against JavaScript and PHP, and assuming without any evidence that all other web languages are just like them if not worse.

I should also point out that I come from a C# background, and that is almost entirely based around object-oriented programming. I tried ASP.NET once, and I could never get my head around MVC with C#, nor PHP for that matter. I shouldn't really tamper on a subject I have little experience with, which may be down to its inherent complexity, but I think of the attempts I have made at trying to understand it for years up to this point shows that it is unnecessarily complex. It may just be my bias toward web development, but I have enough knowledge to know that developing with the Web requires such a different mindset to video game development that it is beyond belief how people can cope.

Personally, I think we should have one programming philosophy that works with all environments. Not in the sense of getting rid of OOP altogether, but considering how traditionally we specified the exact position we wanted entities (objects) to be placed. I still, after seven years of web design, cannot understand why CSS3 cannot centre my elements properly, or why we have floats to align elements left or right, or mix and match `inline-block` and `inline` to get things to fit on rows properly.

Server-side development does not need as much attention as the client-side for how cumbersome the Web is to work with, but I think both should be looked at. Haxe resolves much of the tedious and annoying syntactical "sugar" (to put it lightly) of PHP by not requiring prefixing every variable, or spending hours debugging JavaScript code in your web browser for a simple type mismatch or inconsistent type/value comparisons.

Haxe is not a go-to solution for everything, absolutely not. But I think it is great for Web development and resolves, for the most part, much of the tediousness of JavaScript and PHP.
mmozeiko
Mārtiņš Možeiko
1824 posts / 1 project
#15244 Developing the Web in a different language
6 months ago

I never used ASP, it always looked awful to me. In C# I simply created http server that listened for requests, parsed it, prepared response and wrote back the result. It was very bare-bones. Nowadays I would probably use Nancy instead, I did not know about it back then.
LaresYamoir
14 posts
#15263 Developing the Web in a different language
6 months ago

I'm not much of a web developer myself and certainly not experienced in Haxe. So if you want to make tutorials go for it.
However personally I am more interested in the Webassembly/C++ route, mainly because it opens up the possibility to get away from JavaScript, without directly making every JavaScript based website incompatible. In the current iteration it just reduces the amount of JavaScript "needed".