Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@
* [Some interesting facts](languages/haskell/misc.md)

* [Conclusion](languages/haskell/conclusion.md)

* [Brainfuck](languages/haskell/README.md)

* [Introduction](languages/brainfuck/intro.md)

* [History](languages/brainfuck/history.md)

* [Advantages](languages/brainfuck/advantages.md)

* [Disadvantages](languages/brainfuck/disadvantages.md)

* [Conclusion](languages/brainfuck/conclusion.md)

## End

Expand Down
7 changes: 6 additions & 1 deletion book/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ We have to thank these great people on helping to write this book. Everyone here
- Lucas Parzianello

- [devRant](https://devrant.com/users/lucaspar)
- [GitHub](https://github.com/lucaspar)
- [GitHub](https://github.com/lucaspar)

- Krzysztof Szewczyk

- [devRant](https://devrant.com/users/KrzysztofSzewczyk)
- [GitHub](https://github.com/KrzysztofSzewczyk)
6 changes: 6 additions & 0 deletions book/languages/brainfuck/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Welcome

> This chapter has been authored by Krzysztof Szewczyk "Παλαιολόγος".

Welcome to the Brainfuck chapter! I'd like to let you know a bit more about
this awesome language.
13 changes: 13 additions & 0 deletions book/languages/brainfuck/advantages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Advantages

Generally speaking, currently, Brainfuck is seen as joke language or proof-of-concept language. Therefore, it's not very efficient, nor easy to write.

First of all, it's a really good exercise for your brain! Brainfuck, as the name suggests, is very hard to write and read, but not understand! You don't have to waste a lot of time just to understand this fascinating language, you can view it as Sudoku of programming.

Also, Brainfuck is a great learning tool. You can create code generators, optimizing interpreters, learn JIT & AOT compilation basics, compiler construction (by, for example, creating a compiler from Brainfuck to C or some kind of assembly language to Brainfuck).

Brainfuck is really simple too! It consists of eight instructions so it's really easy to learn.

Let's imagine Brainfuck computer - it would consume a really small amount of power (x86 has wide instruction set, ARM has it tighter, while Brainfuck destroys other real architectures having only eight!) and excel in simple tasks.

Finally, Brainfuck can help to **understand** the basics - how do you multiply two numbers? How do you create a conditional statement? In other languages, it might seem simple, but Brainfuck challenges the programmer creating this unique spirit.
15 changes: 15 additions & 0 deletions book/languages/brainfuck/conclusion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Conclusion

Brainfuck was meant to be a joke language, and it would be reasonable to leave it's as is.

Thinking about Brainfuck in real terms is a bit risky, it's always quicker and easier to program other languages. On the other hand, Brainfuck brings back joy to
programming allowing you to play around with the smallest units of a computer program while leaving language fully theoretical,
not binding it to any definite machine (unlike Assembly, allowing you to feel not only joy while programming, but frustration too).
To program Brainfuck, you'd need just a pencil and a reasonable amount of paper. Of course, you could do the same with other languages,
but it's way less practical.

To play around with Brainfuck you need basically no experience - basic knowledge of maths and decent imagination are going to be
sufficient.

Summing around disadvantages and advantages - Brainfuck is impractical and it shouldn't be considered real language. But there's
nothing bad in playing with it!
11 changes: 11 additions & 0 deletions book/languages/brainfuck/disadvantages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Disadvantages

Let's face it. Brainfuck is esoteric language. It was created as a joke, and conforming to author's will is recommended.
There are many so-called Brainfuck hackers around, but being honest, You can't earn a living programming in Brainfuck.

Brainfuck is too impractical to be using language in real-world cases. Developers would cost way too much and work really
inefficiently. Albeit low abstraction level, Brainfuck is memory and CPU time inefficient (a bit like JavaScript on web),
so it's not very viable to write anything in bare Brainfuck and you'd be better off by using some kind of Brainfuck assembler,
or HLL to brainfuck compiler, but none of the listed can beat pure C implementation instead of Brainfuck one.

Finally, the language is a bit limited - I/O is limited to console input and output, greatly reducing use cases.
12 changes: 12 additions & 0 deletions book/languages/brainfuck/history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# History

Brainfuck was first implemented and described by Urban Müller in 1993, attempting to design a language for which he could write
the smallest possible compiler. The language was inspired by False. Müller decided to name his language brainfuck
(with the initial letter in lower case, although it is now often capitalized). He uploaded the first Brainfuck compiler to Aminet
in 1993. The program came with a readme file, which briefly described the language, and challenged the reader
> Who can program anything useful with it? :)

Müller also included an interpreter and some quite elaborate examples

It is not known was Müller aware of or influenced by Böhm's language P'' (1964), of which brainfuck can be considered a minor
variation.
30 changes: 30 additions & 0 deletions book/languages/brainfuck/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# Introduction

Brainfuck is the most famous esoteric programming language ever made. It's an esoteric language, so it was not meant to be used
in solving real-world problems (but, no one forbids You too!). The language can't be classified clearly. Partly it's a very high-level language - Brainfuck doesn't bind itself to any architecture making it very portable language. On the other hand, it's very
low-level language - it supports only addition and subtraction, basic control structure (`while`-like loop), basic I/O (terminal
only, shrinking capabilities to the absolute minimum), and indefinitely long tape where any byte can be stored arbitrarily. Brainfuck
is Turing complete, meaning that it is in the same computational class as universal Turing machines. This, plus its amount of
instructions, makes it a most popular example of a Turing tarpit. This can be proven in many ways, with various restrictions on
the brainfuck program or interpreter.

Daniel Cristofani wrote universal Turing machine emulator in Brainfuck which is so small we can quote it here:

```bf
+++>++>>>+[>>,[>+++++<[[->]<<]<[>]>]>-[<<+++++>>-[<<---->>-[->]<]]<[<-<[<]+<+[>]<<+>->>>]<]<[<
]>[-[>++++++<-]>[<+>-]+<<<+++>+>[-[<<+>->-[<<[-]>>-[<<++>+>-[<<-->->>+++<-[<<+>+>>--<-[<<->->-
[<<++++>+>>+<-[>-<-[<<->->-[<<->>-[<<+++>>>-<-[<<---->>>++<-[<<++>>>+<-[>[-]<-[<<->>>+++<-[<<-
>>>--<-[<<++++>+>>+<-[<<[-]>->>++<-[<<+++++>+>>--<-[<->>++<[<<->>-]]]]]]]]]]]]]]]]]]]]]]<[->>[
<<+>>-]<<<[>>>+<<<-]<[>>>+<<<-]]>>]>[-[---[-<]]>]>[+++[<+++++>--]>]+<++[[>+++++<-]<]>>[-.>]
```

Simulation is one way to prove Turing completeness:

> If an interpreter for A can be implemented in B, then B can solve at least as many problems as A can.

There are some difficulties with this way of proving Turing completeness (ℒ), but for Brainfuck, it's entirely sufficient. By theory,
it's ℒ-complete too, so the proof is fully valid.

Brainfuck is an amazing language. One must still understand where it would be suitable, and where it doesn't particularly excel
at.