Viewing a single comment thread. View all comments

mima wrote

Reply to comment by SnowCode in UPDATE by readinglistmirror

Rust is fine for systems programming, but web development? Please no. And that goes for other compiled languages too. Just use PHP which is designed for that purpose.

4

SnowCode wrote (edited )

I don't see why it would be a problem actually. Rust is meant to be general purpose and it's really fast. I don't see why it would have to be PHP.

Honestly I don't see any reason to not use Rust, of course you can prefer another language but I don't see any inherent problem at using Rust for web Dev. Quite the opposite actually.

3

mima wrote (edited )

Well just because it's general purpose doesn't mean you should use it for everything. :P Sure, Rust can do the job, any compiled language can be used for web dev, but are the trade-offs worth it? Compiled code from Rust does go fast, but building Rust code is painfully slow in my experience. IMO, development time should always trump out performance. And if you need more performance in PHP, JIT compilation is most likely enough for your use-case anyway.

PHP afaik is memory safe, so even in that front Rust doesn't provide any benefit. And you will still have to sanitize user inputs (which is the more prominent threat you have to deal with) whatever language you're using anyway...

So really I don't see any reason why one should deal with low-level stuff in web development. If you're writing a database like MariaDB, sure code that in Rust. But something that interfaces with the web like MediaWiki and Postmill? Just code it in a tried, tested, more mature language that is written for that exact purpose like PHP.

1

SnowCode wrote (edited )

I don't feel like building stuff in Rust is slow, it's maybe just a question of being used to it.

Also in Rust a lot of things are done by the compiler. I asked some people that know more about web Dev in rust than me about it. And they said for instance, when you handle SQL, the compiler will check the SQL requests against a dev database to ensure they are valid. Other than that, Rust forces every single case to be handled, and has a very rich type system in order to make things that shouldn't exist impossible to represent in the program. This is all done for errors to happen at compile time instead of runtime to make the programs as reliable as possible.

For SQL again, sqlx supports and forces the use of prepared SQL queries to sanitize user input.

In a nutshell, Rust is built for being fast AND as reliable as possible, by preventing many errors from happening at runtime. So in that sense it seems Rust is more reliable than PHP.

4

emma wrote

I don't feel like building stuff in Rust is slow, it's maybe just a question of being used to it.

PHP has a unique execution model where an interpreter (usually an Apache module or php-fpm, a FastCGI server) sits and waits for incoming requests, then executes the script corresponding to the request and cleans up everything (global/class variables, runtime settings, etc.) after it. I've not developed in Rust, but I have in Python and Node, and having to deal with reloader tools to achieve the same 'save file, switch to browser, reload' development cycle is just painful in comparison--either they're too slow to act on changes, too fragile, or both.

In terms of runtime performance, this execution model is slow due to having to bootstrap the framework on every request, but assuming you used an HTTP abstraction like PSR-7 or Symfony's HttpFoundation, you always have the option of using an application server that preserves state between requests. The reverse, having the option to interpret on demand, is not true when developing web applications in Rust.

In a nutshell, Rust is built for being fast AND as reliable as possible, by preventing many errors from happening at runtime. So in that sense it seems Rust is more reliable than PHP.

I don't think anyone would dispute this. However, if you're disciplined and use types and type hints throughout your PHP code, you can use static analysis tools to obliterate whole ranges of programming errors, just like with Rust's compile-time checks. They aren't nearly as complete, sure, but the faster pace of development achievable with PHP, not to mention its rich ecosystem for web development, make this a tradeoff worthy of consideration.

6