Rapidly create native Windows and macOS GUI applications (The Red programming language)

in #programming7 years ago

Did you ever wonder what programming would be like if it was fun and simple? If writing graphical applications didn’t require you to write hundreds of lines of code for even very basic apps, or require the use of trickery like cross platform GUI toolkits or web views wrapped up in an app that mimic the look and feel of native applications but never feel completely right and are always a bit slow, use up tons of RAM and result in huge binaries?

Did you ever wonder if the complexity of the tools we use to program today is not because programming is inherently that complex, but because the tools we use might just be bad?

Well, wonder no longer! Because here comes the Red programming language.

red_logo.png

A few quick example GIFs

output (1).gif

At the end there I try to show a bit how layouting works. There are different words you can use like return in the GIF to go to the next line. Across lays out the widgets that come after it horizontally, below does it vertically. At 100x100 allows you to position a widget at an absolute position.

The following small examples use Red’s reactive GUI programming feature. Reactivity decreases the amount of glue code you have to write to hook up different widgets, or faces as they are called in Red, compared to hooking up event handlers manually.

A text area that counts the characters that you type live while typing:

output (5).gif

Three sliders used to change the RGB color of a rectangle drawn to the screen:

output (3).gif

Here is another slider, but this time it’s hooked up reactively to the radius of a circle drawn to the screen:

output (4).gif

Download

Amazed yet? Try it out for yourself, it’s free and open source. You don’t need to install anything, just download the tiny 1 MB binary for Windows or the macOS binary, double click the file to start a REPL (read eval print loop) and start writing programs! Here is a getting started guide, a website with small little example apps like I showed you in the GIFs, and another one.

The macOS binary I link to is the latest development version, official support for macOS GUI apps is planned for version 0.63, but the dev version usually works just fine, so just give it a try if you don’t have access to a Windows machine. You’ll have to do a chmod +x on the file to give it executable permissions and you need to use the Mac version from the terminal, you can’t just double click it to open Red’s own console yet.

Compiling apps

The resulting apps if you compile them are fully native, no other dependency needed, small file size. Compilation (from the command line) is just as easy as the rest of Red: red-062.exe -r yourfile.red

-r tells Red to compile in release mode (debug mode using -c instead of -r compiles faster, but for distribution of your app you want release mode)

This will create a yourfile.exe file in your current directory (or yourfile.app for macOS).

Write red-062.exe -h to see a list of all the command line switches. Providing just a file name without any switches executes the Red file without compiling it to a native app first, so that’s what you’d use during development to quickly try out changes you make.

Red does cross compilation, so you just need one build computer to output apps for all platforms. This is how you would compile for Windows on a Mac: red -r -t Windows yourfile.red

What can you do with Red?

Red isn’t just for GUI apps. Red calls itself a full stack language. You can write very high level things with it like GUI desktop apps. You can write console scripts. You can at some point in the future even write client side web apps and Android and iOS mobile apps with it. It will also interface with the Java and the .Net platforms. But you can also go to the lowest level, write drivers or whole operating systems. In that way it’s a full systems programming language like C/C++, not just a scripting language like Ruby or Python, but is still as easy to use as those are (and even easier in some regards).

“That’s impossible!” you say? No. But it’s a bit of a trick :) Red is very good at creating domain specific languages, called dialects in Red. In fact, the GUI code I’ve shown you in the GIFs wasn’t just Red, it was a dialect called VID, which makes writing GUI apps really easy (but you can always go a level deeper if you need to do more complex stuff).

There are many more dialects (and you are encouraged to write your own), one of them is Red/System. Basically a subset of Red, the syntax is the same, but you don’t have all of Red’s features and datatypes available. Red/System is very fast and allows you to write really low level stuff like drivers. While Red is garbage collected, Red/System uses manual memory management like C. You can write Red/System inline in your Red scripts, to make just specific things faster, and you can inline assembly language in Red/System if you need even more speed in a tight loop.

What kind of dialects can you write? Well, Red is the spiritual successor (meaning inofficial, there are others too) of a language called Rebol. It’s basically 90% the same syntax and concepts, but modernizes it, moves away from being an interpreted language using its own cross platform GUI toolkit to fully native compiled apps and adds lots of features. One of the more advanced dialects for Rebol allows you to write Rebol code and output it as Flash. The famous indie game Machinarium was created using that dialect. So the whole game was written in Rebol, and then just compiled to Flash to make it run everywhere. There is also a dialect that lets you easily write PDF files, HTML, etc. Really cool stuff.

What makes writing dialects in Rebol and therefore also Red so easy is yet another dialect, called parse. Parse does in Red what regular expressions do in other languages. It’s extremely powerful and much easier to deal with than regular expressions. A dialect written in parse is very readable. Check out this article on Red’s website to see some examples of parse in action to parse IP addresses, email addresses, HTML, etc.

This stuff is too awesome, what is the catch?

Red is still in development (version 0.62 right now) and has been for quite a few years now (six I believe), it’s a big (and very active) project! It’s perfectly usable right now, but some advanced features are still missing, like dealing with low level I/O like network ports. Regardless of that, you can already do a lot with it and even if you can’t use it yet because some specific feature you need is still missing, you should keep an eye on this language, it’s amazing, a joy to use and just so versatile. You can also always resort to using Red/System if you need something Red doesn’t provide yet. Red/System’s FFI can interface with any of the myriad C libraries out there, the community created quite a few bindings to popular languages already that you can check out here, just scroll to the bottom.

What type of language is Red? Object oriented? Functional?

Red is paradigm agnostic (basically multi paradigm, but even more so). Red has roots with the Rebol language and Rebol has roots with the Lisp language (Rebol used to be called Lisp without the parentheses), but looks very different from that particular root in it’s current form. You can do object oriented programming, functional programming, imperative programming, whatever you want, Red bends to your whim, not the other way around (especially when it comes to dialects). Just like Lisp, Red is homoiconic, code is data and data is code and Red even takes that a bit further. Allows for some really cool stuff, or so I’ve heard, I’m neither a Red nor a Lisp expert :) If you like macros, Red got macros.


If I got you interested, go check out the Red website, read some tutorials, look at example applications, and above all: Have fun!

I’ll also be writing some Red tutorials here on Steem soon, maybe I’ll even do a video, so feel free to follow me if you’re interested in that. I’m still learning the language myself, so we’ll learn it together ;)

Sort:  

Red is fantastic!

I allready knew Rebol, but recently I discovered RED.

This definitively is the future of programming!

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 63540.43
ETH 2481.91
USDT 1.00
SBD 2.66