Learn Red – Fundamentals of Red
eBook - ePub

Learn Red – Fundamentals of Red

Get up and running with the Red language for full-stack development

Ivo Balbaert

Buch teilen
  1. 252 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Learn Red – Fundamentals of Red

Get up and running with the Red language for full-stack development

Ivo Balbaert

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Discover how to use the next-generation language Red for full-stack development, from systems coding over user-interfaces to blockchain programming

Key Features

  • Explore the latest features of Red to build scalable, fast, and secure applications
  • Learn graphical programming and build highly sophisticated reactive applications
  • Get familiar with the specific concepts and techniques of Red development, like working with series, viewing code as data, and using dialects.

Book Description

A key problem of software development today is software bloat, where huge toolchains and development environments are needed in software coding and deployment. Red significantly reduces this bloat by offering a minimalist but complete toolchain. This is the first introductory book about it, and it will get you up and running with Red as quickly as possible.

This book shows you how to write effective functions, reduce code redundancies, and improve code reuse. It will be helpful for new programmers who are starting out with Red to explore its wide and ever-growing package ecosystem and also for experienced developers who want to add Red to their skill set.

The book presents the fundamentals of programming in Red and in-depth informative examples using a step-by-step approach. You will be taken through concepts and examples such as doing simple metaprogramming, functions, collections, GUI applications, and more. By the end of the book, you will be fully equipped to start your own projects in Red.

What you will learn

  • Set up your Red environment to achieve the highest productivity
  • Get grounded in Red, gaining experience and insight through many examples and exercises
  • Build simple, compact, and portable applications
  • Analyze streams of data through Parse
  • Compose GUI applications with View and Draw
  • Get prepared for smart contract blockchain programming in Red

Who this book is for

This book is for software developers and architects who want to learn Red because of its conciseness, flexibility, and expressiveness, and more specifically for its possibilities in GUI apps and blockchain / smart contracts programming. Some knowledge of the basic concepts and experience of any programming language is assumed.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Learn Red – Fundamentals of Red als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Learn Red – Fundamentals of Red von Ivo Balbaert im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781789133653

Using Functions and Objects

This chapter is about modularizing code through the use of functions and objects.
We have already encountered a lot of built-in functions, such as print and cd, but of course you can write user-defined functions as well. When a program's code gets longer and more complex, you want to be able to give a name to certain code segments. For example, when processing a data stream from a file or the network, you'll want to have a process-request or process-record function that contains the logic of dealing with one chunk of data. That way, you can call this function each time you need it. This leads to less code that is better structured and more readable. Less code means fewer bugs! Functions can take parameters, local variables, and refinements, and we'll be exploring how to use these later on in the chapter.
Another way to group code is to define an object. Red is not class-based, like most object-oriented languages in common use today, such as Java, Python, C#, or Ruby, it takes a more prototype-based approach, where new objects can be created on the basis of an already existing object—its prototype. In this chapter, we will explore what you can do with objects in Red in depth.
In this chapter, we will cover the following topics:
  • A fauna of functions
  • Function attributes
  • Working with functions
  • Code is data and data is code
  • Using objects

Technical requirements

You'll find the code for this chapter at https://github.com/PacktPublishing/Learn-Red-Fundamentals-of-Red/tree/master/Chapter06. If you have installed Red as indicated in Chapter 2, Setting Up for Development, you are good to go. You can work on Windows, OS X, or Linux. You can type or paste any code in the Red console to see its results, or you can use an editor, such as Visual Studio Code.

A fauna of functions

Red's built-in functions can be categorized as follows. The type is indicated within ():
  • operators (op!), which can be used with infix notation, such as a + b, a / b, and so on.
  • native (native!) functions, such as if, either, while, throw, all, wait, and so on; you can see a complete list by using ? op! in the console.
  • routine (routine!) functions, such as exists?, write-clipboard, and so on; you can see a list using ? routine! It is also used in Red to define a function that calls a Red/System function (see Chapter 10, Advanced Red).
  • action (action!) functions, such as copy, move, clear, to, form, and so on; you can see a complete list using ? action!
The native, routine, and action functions are written in Red/System. Action functions are special in that they are polymorphic—they are defined for more than one datatype. Which action code is executed depends on the type of its first argument.
  • mezzanine (function!) functions, which are higher-level functions written in Red; you can see a complete list using ? function!
In this section, we'll cover the variety of ways that exist to define your own functions.

The do word

We will start by giving a name (a label) to a code block so that you can call that code by its name and evaluate it with the do word, which we already saw in action in the Evaluation with do and reduce section in Chapter 3, Using Words, Values, and Types. Here, the word pri5 is bound to a piece of code, which prints five digits separated by dashes:
;-- see Chapter06/do-does-has-func.red:
pri5: [
repeat i 5 [prin i prin "-"] ]
do pri5 ;== 1-2-3-4-5- ; evaluate code block with label pri5
t...

Inhaltsverzeichnis