News for hackers. Stuff that matters.
Re:When Does a Project Need React? by bmer on Monday April 24, 2017 @01:21PM (#14186113)
I don't do any web-dev, so I apologize for the simplistic question: what alternatives to JavaScript exist for web-dev? The article hints to there being many alternatives, and that JavaScript may not be right for every project...but I can't think of any alternatives.

Python? C++? Do these languages have strong support for web stuff?

Re:When Does a Project Need React? by elevensies on Monday April 24, 2017 @02:43PM (#14186849)
One "alternative" is to do the minimum possible in the browser, and do most of the work on the back end.

For example, if you inspect this page, you'll see that it has about 150 lines of Javascript.

There are two ways to change a webpage:

- manipulate it with Javascript

- reload a new page with the changes applied

If your page loads quickly and not all that often, you can get pretty far without Javascript. If you are willing to tolerate a pageload on each interaction, you don't need any Javascript.

Re:When Does a Project Need React? by jasode on Monday April 24, 2017 @03:04PM (#14187045)
>If your page loads quickly and not all that often, you can get pretty far without Javascript. If you are willing to tolerate a pageload on each interaction, you don't need any Javascript.

To put some concrete examples to that...

The HN page uses javascript[1] for the upvote/downvote buttons and also to collapse/expand comments. It would be very disruptive and jarring to reload an entire page after someone clicks a vote button. Also, mobile phone users would be doubly punished since a page reload is slower than desktop highspeed internet.

A good example of a website not requiring javascript without penalizing user-interface usability is Wikipedia text pages.

[1] https://news.ycombinator.com/hn.js

Re:When Does a Project Need React? by GuiA on Monday April 24, 2017 @02:50PM (#14186912)
This advice only applies for non interactive stuff though. What if I want to build a spreadsheet, audio editor, vector-based illustrator, etc. in the browser?
Re:When Does a Project Need React? by elevensies on Monday April 24, 2017 @03:07PM (#14187073)
Yeah, if the system can't be represented as hyperlinked documents, then you're going to be married to the browser APIs which are in Javascript -- so you can either use Javascript or a tool that outputs Javascript.
Re:When Does a Project Need React? by pitaj on Monday April 24, 2017 @02:07PM (#14186529)
You can use ClojureScript, Elm, TypeScript, or a myriad of other compile-to-JS languages on the frontend. You can use anything on the backend, but React server-side rendering only runs on Node.js AFAIK.
Re:When Does a Project Need React? by vmasto on Monday April 24, 2017 @02:11PM (#14186563)
but React server-side rendering only runs on Node.js AFAIK.

There are a few solutions for Ruby, PHP and Python although I have no experience with them and how well they perform/work.

Re:When Does a Project Need React? by drdaeman on Monday April 24, 2017 @03:13PM (#14187143)
Unless it's some real magic (please share if it is), I believe the best they can do is either spawn a node process from Ruby/PHP/Python, or use embedded v8 or similar interpreter. Which is not any different from running node "the normal way".

React is implemented in JS and uses JS to declare components, and it would be fun if there is some working JS-to-Python (-to-PHP/-to-Ruby) translator that is good enough to translate React code to run "natively".

Re:When Does a Project Need React? by vmasto on Monday April 24, 2017 @03:30PM (#14187305)
Oh yeah you're absolutely right of course. Not saying it doesn't run V8 or some kind of interpreter in the background (I actually have no idea how they work), just think that's abstracted away and I don't think there's any JavaScript setting up required from the developer.
Re:When Does a Project Need React? by TimJYoung on Monday April 24, 2017 @02:54PM (#14186946)
Our product, Elevate Web Builder, allows you to develop single-page web applications using Object Pascal. It uses a component-based approach to development along with WYSIWYG design (drag a component/control from the component palette and drop it on a designer) and a compile-to-JS compiler.

You can see an example of the various controls here:

http://www.elevatesoft.com:8081/controlsdemo/controlsdemo.ht...

The code for the example is here:

http://www.elevatesoft.com/controlsdemo_code.txt

Most of the code is either a) auto-generated by the IDE (all non-private/public interface code, and all event handlers), or b) part of the "particles" canvas drawing code.

Re:When Does a Project Need React? by rpeden on Monday April 24, 2017 @04:34PM (#14188043)
Looks like an interesting product, Tim. I've always enjoyed Pascal so I'll give your trial version a try.
Re:When Does a Project Need React? by TimJYoung on Tuesday April 25, 2017 @08:56AM (#14193002)
Thanks very much. If you have any feedback or questions, please feel free to contact us at [email protected] . We're always looking for constructive feedback, especially if you normally use plain JS/HTML/CSS for coding or use a JS framework like Angular or React.
Re:When Does a Project Need React? by callahad on Monday April 24, 2017 @02:23PM (#14186681)
Elm (http://elm-lang.org/) is a particularly elegant language for front-end web development that compiles to JavaScript, but includes things like immutability and strong, static typing right out of the box.

Other languages like C, C++, and Rust can also run on the Web thanks to WebAssembly, a new compiler target for the web that's on by default in Firefox, Chrome, and Safari Technical Preview, and available behind a flag in Edge: http://caniuse.com/#feat=wasm However, interaction between the DOM and WebAssembly is still pretty rough, so it's currently best at numeric / computationasl tasks, not replacing JavaScript entirely.

Re:When Does a Project Need React? by majewsky on Monday April 24, 2017 @07:34PM (#14189432)
I have a friend who's currently doing a web frontend for an HPC application in C++ with Wt [1]. It's trying to be like Qt on the desktop; basically all events are sent from the frontend to the backend and handled there, in a normal C++ application. Then the widgets render their updated state and that gets sent back to the browser for integration into the client-side view. Then you're just building applications out of widgets like with a regular old desktop application, which my friend is really happy about since he has a bit of experience with Qt and the like, but absolutely zero experience with HTML/CSS/JS.

[1] http://www.webtoolkit.eu/

Re:When Does a Project Need React? by tboyd47 on Monday April 24, 2017 @02:44PM (#14186865)
Usually you have a client/server architecture where HTML for the site is generated on the server by a multithreaded language. Practically any language can be (and is) used for this, like Perl, Python, PHP, C++, Java, Go, Ruby, C#, Scala, Clojure, Erlang, etc. It's to the point where it feels like literally every language has been used for web dev somewhere. And of course, Javascript, too.
Re:When Does a Project Need React? by GhostVII on Monday April 24, 2017 @01:35PM (#14186241)
JavaScript is basically the only option for front end web dev (unless you do web assembly, but that's pretty new). There are lots of different JavaScript frameworks that you can use, including react, so I think they are referring to the alternative frameworks rather than languages.
Re:When Does a Project Need React? by vmasto on Monday April 24, 2017 @02:09PM (#14186541)
Certainly not the only language, see my reply above (or below depending). There are a lot of great languages which either compile to JS perfectly or have been built with that purpose in mind.
Re:When Does a Project Need React? by cholantesh on Monday April 24, 2017 @05:15PM (#14188361)
Does WebAssembly actually replace JS or is it another language that compiles into it?
Re:When Does a Project Need React? by vmasto on Monday April 24, 2017 @02:07PM (#14186527)
For front-end development some strong options in different languages are: Elm, TypeScript, Reason, Coffeescript (although Coffeescript usage has fallen dramatically every since the newer versions of JavaScript added a lot of its great features).
Re:When Does a Project Need React? by robojamison on Monday April 24, 2017 @01:32PM (#14186209)
Python does, and C++ "does". Python has Django and other frameworks, C++ has CGI...but people usually avoid using it if at all possible. The most commmon languages for web development are: HTML, CSS, JavaScript, PHP, Ruby, and Java.
Re:When Does a Project Need React? by vinceguidry on Monday April 24, 2017 @02:43PM (#14186855)
I'm enjoying using Hyperloop where you write Ruby everywhere.

http://ruby-hyperloop.io/