
The Chaos Programming Language - mertyildiran
https://chaos-lang.org/
======
staticassertion
I started going through the docs. This language starts off with some heft
sells - prevent errors, increase test coverage, etc. Then the docs mostly
cover things like "you can call an array an array or a list" and stuff that
isn't very interesting to me.

It doesn't even show methods or things like that. I think 90% of the docs I've
read so far should have just been a single page with one liners one after the
other, and less interesting stuff that's got more depth should go further
back. I don't think showing nested arrays and dictionaries is interesting to
me after you've just told me about some super interesting testing /
correctness stuff - lead with that!

I skipped ahead to Decision Making. I think the example is so strange and
contrived - three functions, each returns some number above 100, some logic
after that that feels arbitrary? I would do something at least a little more
universal like fib.

The end of this section states "100% testable" \- I'm confused. Why is this
testable?

I could not write one unit test to have 100% code coverage, not even line
coverage.

If I, for example, wrote a test that used the code provided, with an assertion

assert add(3, 5) == 101

I would not hit f2 or f3, so I'm confused by: "A single unit test is enough to
have 100% coverage on functions, always."

That unit test was definitely not enough for 100% coverage.

I skimmed the rest.

For a language that states it's great for testing and preventing errors, I am
at a loss as to how one would write a test for it, or handle an error.

This looks like a pretty neat language, but you really gave me such a good
hook and then no follow through.

~~~
rrobukef
Since there are no if's (except at the end), every line is executed. Since all
if's at the end can be placed on a single line, you have 100% _line_ coverage.
I don't think this language is very serious.

~~~
MaxBarraclough
As you say, this doesn't sound right. If you force the programmer to write
branch-free code (this appears to be the founding principle of the language
[0]), that doesn't mean your boundary-value analysis [1] problems go away, it
means you've made them less explicit.

As you say, there's full _line_ coverage for tests, but no guarantee of full
equivalence-partition coverage. It's quite possible for branch-free code to
fail on certain values. ctrl-f for _overflow_ in [2]

The 'Showcase' link is broken, the GitHub repo seems to show no examples, and
the linked StackOverflow _chaos_ tag is never used in relation to this
language, so as you say, I'm not sure how serious this language really is. Fun
idea though.

(It's entirely possible I'm misusing the term _boundary-value analysis_.
Corrections welcome.)

[0] [https://chaos-lang.org/docs/11_decision_making](https://chaos-
lang.org/docs/11_decision_making)

[1] [https://en.wikipedia.org/wiki/Boundary-
value_analysis](https://en.wikipedia.org/wiki/Boundary-value_analysis)

[2]
[https://graphics.stanford.edu/~seander/bithacks.html](https://graphics.stanford.edu/~seander/bithacks.html)

------
winstonewert
Did anyone else think this was a joke language at first? My initial impression
was that it was an esoteric language which was tongue-in-cheek passing of its
oddities as language features.

Firstly, there's the name: chaos, which evokes the opposite of what my code to
look like.

Secondly, the first three "features" all come across as deliberately goofy to
me. The first two promise seeming implausible things: zero cyclomatic
complexity and always 100% test coverage. The justifications for these
promises seem bizarre: only function returns allow decision making? (A
seemingly terrible place to make decisions) One test is always sufficient to
have coverage? It isn't object-oriented? (Obviously, a lot more to functional
then that)

~~~
progval
> Firstly, there's the name: chaos, which evokes the opposite of what my code
> to look like.

The full name is "The Chaos Programming Language", which I understand as "the
language to program chaos". It's in line with the motto "Turn chaos into
magic!", as you program to turn an arbitrary state (chaos) into what you want
(order / magic).

I still think it's a joke language, but this part is well-thought.

------
catlifeonmars
The fact that there are two aliases for each (most?) builtin types immediately
turned me off. Maybe there’s a good reason for that particular feature of the
language, but I would not throw that at a prospective user in the getting
started guide.

------
dilippkumar
From [https://chaos-lang.org/docs/11_decision_making](https://chaos-
lang.org/docs/11_decision_making)

> Decision making(a.k.a. control structures) in Chaos language is only
> achievable on function returns for the sake of zero cyclomatic complexity.

...

> At first glance, defining the control structures in this way might seem so
> unnecessary or inconvenient but this is the pinnacle of writing 100%
> testable, clean and error-free code in any programming langauge by far.

I’m skeptical about this claim. I’m not sure I believe 100% error-free is
possible in any language.

Can someone please elaborate on this claim?

~~~
curryhoward
I agree with the other commenter about the comma in this sentence. But I'd
also like to point out that 100% error-free code is possible. There's a whole
branch of computer science dedicated to it: formal verification. I personally
have used Coq to write certified code in the past, and I'm quite confident
that my code was 100% error-free.

Of course, there are some qualifications one should make regarding such a
claim: you have to trust that your specification is "correct", that your
hardware is functioning correctly, that the proof checker didn't accept a
bogus proof, that the underlying logic (e.g., the calculus of inductive
constructions) is consistent, etc. That's a lot of things to trust, but the
point is that you don't have to trust yourself.

~~~
whatshisface
I really can't trust myself to write a specification. I know this because I
have written errors in tests before - even when all I'm doing is trying to
work out some properties that the answer ought to have, I can still make a
mistake. It's just usually less likely that I would make a mistake, because
the specification is simpler than the algorithm.

So, it is not really fair to downplay the chance that you could have a wrong
specification, although it would be equally wrong to use that as an excuse to
downplay the value of Coq.

~~~
rrobukef
WPA2 is a formally verified protocol. It lasted 14 years:
[https://www.krackattacks.com/](https://www.krackattacks.com/). Now it's
partially formally verified.

~~~
danielscrubs
You can't prove that something is secure, because to be applicable in
mathematics/computer science there has to exist a precise definition.

If someone is just saying "This is a formally verified protocol" without what
they actually checked for, they are salespeople not mathematicians.

"The authors of the KRA paper were able to understand what the proofs were
about, and why they don’t cover the KRACK vulnerability. Even though the
original proofs didn’t reveal security flaws, a principled approach would use
these proofs in order to discover where to look."

[https://galois.com/blog/2017/10/formal-methods-krack-
vulnera...](https://galois.com/blog/2017/10/formal-methods-krack-
vulnerability/)

------
pmontra
It's the first time in many years that I look at a new language and it feels
good. I had no WTF moment, thinking "how could a human mind came up with
this?" or "why do they want us to feel miserable doing that?"

I only wonder how it would feel using it on real world problems.

One question to the author: is there string interpolation?

    
    
      world = "world"
      print "hello #{world}"
    

Finally, the links in the Docs section of the footer are 404 and the link to
GitHub links the home page of GitHub, not the project.

------
andrewflnr
Cyclomatic complexity is a whole-program property. Your functions are just
nodes in the control flow graph, where the real complexity appears. One-branch
functions are definitely a good hack, though. :)

~~~
jolux
One might even go so far as to say that the whole program is a function :)

------
jedberg
> Every variable in Chaos language is immutable by default.

\---

> kaos> num a = 5

> kaos> a = 7

> kaos> print a

> 7

Doesn't that mean a is mutable by default?

~~~
abiogenesis
No, it only means that you can reassign the name `a` to a different value
(i.e. it is a variable, not a constant).

It would be mutable if it allowed something like this:

    
    
        > a = 5
        > a.add(1)
        > print a
        6
    

Note that numbers are immutable in most languages anyway. Arrays, hashmaps,
and sometimes strings are the data types that are frequently mutable.

~~~
eyelidlessness
Numbers are literally _never_ immutable in any language that isn't designed
intentionally for comedy. _Variables_ of a number _type_ may be mutable, but
the numbers themselves never mutate. Strings are _typically_ immutable in most
languages, but that does vary some (generally surprising people who expect
primitives to be immutable).

~~~
stellalo
For a moment I started imagining what a mutable number would be like:

> 3 = 5

> print 3

5

The end

~~~
tralarpa
You can kind of do that in Java by manipulating the integer cache

------
golergka
As far as I understand after reading the docs for 5 minutes, this section is
the core original idea behind the language:

[https://chaos-lang.org/docs/11_decision_making](https://chaos-
lang.org/docs/11_decision_making)

> Decision making(a.k.a. control structures) in Chaos language is only
> achievable on function returns for the sake of zero cyclomatic complexity.

This looks as original and language-defining as Rust's borrow checker. I
really wish authors changed their docs accordingly. Everything else is pretty
standard on a conceptual level, but this still has me thinking whether it's a
work of pure genius, a joke language or both.

~~~
mertyildiran
Yes, you are correct. The very intuitive approach we took on decision making
is the key point of the language.

I came up with this idea of designing a language with no "if" after dealing
with various untestable codebases for years. They were literally untestable
because of the technical debt caused by the extensive amount of "if" usage in
the function bodies, especially the guard clauses makes it 1 "if" minimum for
almost every functions. So at the end I have exhausted because of the if(s)
and decided to create a language that forces you to have minimum technical
debt.

~~~
jandrese
I'm still not convinced it doesn't just sweep the complexity under the rug.
Ultimately you still need to branch unless you only want the language to do
pure mathematical computation or something like that. Only now every branch
needs to be hidden in a function call.

~~~
pmontra
I have a large Elixir project with less than 10 branches (if then else) and
they were written by other developers. Conditional logic is done either in
pattern matching in function definitions (and some guard) or case/cond or
with/else.

I guess case/cond can be implemented with the return mechanism of Chaos. Maybe
it's going to feel weird, maybe not.

There is no pattern matching and I got the feeling that's going to complicate
things but again, it can be emulated to some degree but the return mechanism.
Instead of

    
    
      def a(0), do: "a"
      def a(1), do: "b"
      def a(_n), do: "c"
    

Probably we'll be writing

    
    
      str def a(n)
        num x = n
      end {
        x == 0 : "a"
        x == 1 : "b" 
        default: "c"
      } 
    

Having to define that x variable feels like a waste of code and reasoning on x
instead of n (the argument of the function) is a pity. Maybe the function body
can be empty. I didn't install the language.

I wonder how that scales on real world cases, for example matching the
internals of some complex data structure.

~~~
curryst
Pattern matching is still branching. An elegant way of expressing it, but it
is branching none the less.

------
remcob
Creative idea! There are no branches or closures, but the language does allows
loops and recursion. These have non-zero cyclomatic complexity. A loop with
either 0 or 1 runs is basically an if statement.

------
rafaelvasco
Seems like we have a fellow Chaos Magick practitioner right here. Funny that
the creator named the language "Chaos", the module manager "Occultist" and the
modules "Spells". Now I can't dislike it even if I found some of the language
features quite alien.

~~~
jandrese
> I found some of the language features quite alien.

You might even say they are arcane.

~~~
rafaelvasco
Ahaha. Perfect :)

------
azhenley
I can't really find any examples. I wish the homepage showed one.

This page shows how to do an add function: [https://chaos-
lang.org/docs/11_decision_making](https://chaos-
lang.org/docs/11_decision_making)

~~~
_bxg1
Yeah, you have to dig several pages deep into the tutorial before you see
meaningful code examples that distinguish it from other languages. This is a
mistake that language websites make way too often.

------
thiht
Having 2 to 3 keywords for the exact same purpose seems like a nightmare. Do
we need `def`, `fun`, and `function`? Just pick one and only one.

On another note, the docs are not so good. They're really missing a few real
life examples with unit tests.

~~~
choward
This alone made me stop reading. There is absolutely no reason for this. It's
an extra thing I have to think about when reading/writing code with literally
zero benefit. Now people new to the language have extra stuff to learn.
Languages need less ways to do the same thing. Not more.

------
souenzzo
Please explain how operate with collections

how do I create a new array with a new value

there is GC or Structural Sharing?

Also, there is lambdas? Force the developer to create a function for each
"conditional" loop costs the habit of bad function naming.

------
amdelamar
Looks neat. One recommendation, before the section "Influenced by", could you
put a code snippet of what Chaos would look like? It can be HelloWorld, but a
more real-life example would be appreciated. (A few example sites that do
this: [https://vertx.io](https://vertx.io), [http://www.scala-
js.org](http://www.scala-js.org))

------
gitgud
> Decision making(a.k.a. control structures) in Chaos language is only
> achievable on function returns for the sake of zero cyclomatic complexity.

This is just moving the control flow to the end of the function right? Switch-
case statements also have cyclomatic complexity, right?

------
gorpomon
I appreciate the minor insight provided by seeing a language where control
structures can only happen upon function return. I've had to teach recursion
to many beginning students, and I have a feeling that seeing something like
the Chaos language would help the concept of recursion gel with them. I'm very
unsure that the language itself is useful or good, but I was certainly
delighted by that small bit of insight.

Maybe some unix pros here can tell me, why the occultist package manager not
installed via sudo, but the language itself is? It seems like an unnecessary
security risk to run sudo on a random download.

------
fn_esc
no-branching is an interesting concept, but that’s not what “immutable” means.
also, why are there 3 synonyms for every single keyword?

~~~
mertyildiran
Thanks a lot for finding the way Chaos language handles the decision making,
interesting.

There are a lot of alternative keywords, especially for type safety and
function definition related keywords, with the purpose of attracting
programmers from other programming languages and making them feel at home. At
least that was the intention.

~~~
golergka
No language I have ever worked with allowed a codebase with intermixed
keywords for defining a function. In terms of feelings, it's as alien as it
can get.

------
olodus
Interesting idea. I mostly agree with limiting the amount of control flow. I
generally try to avoid as many ifs as possible.

It isn't that alien of an idea in my mind as most people here in the comments
seem to argue. I suppose if you used a function with only an "end" clause a
function would end up mostly like how one generally writes functions in most
functional languages, where a lot of functions are fully comprised of a
switch/match on the input. Maybe because the syntax is very Ruby-like you see
a lot of people here expecting more object-oriented design.

------
isaiahg
I think the concept of having conditionals at the end of functions is more
interesting than people here are giving credit. It could go a long way to
getting rid of incomprehensible nested if statements.

But all the aliases need to go. What's the point of having three aliases for
an import statement other than to confuse new programmers. It seems like one
of those ideas that seems good on paper, to include words from first
languages, but in the end it'll just end up confusing everybody.

------
rurban
Extremely simple and powerful. Functional languages are really superior.

The only thing I dislike are the blinking colored messages.

And maybe the list alias for array is extremely confusing, esp. when he wants
to add real lists later. Or lazy lists. json for dict maybe, why not.

------
nerdponx
What's with hard-coding the installation to /usr/local?

I'd rather have another "dot directory" like ~/.occultist than have some
random package manager take over my entire /usr/local.

------
tohuvavohu
The "Hello World" example says to run "hello.kaos" with "$ chaos dev.kaos".

Is the renaming from hello.kaos to dev.kaos intentional?

------
smoyer
Can this be compiled (and minimized) at some point or are we stuck with an
interpreter?

------
danielscrubs
You know those programmers that confuse CS and programming? This is what I
imagine they would come up with as they just don't have the tools of
formality.

------
unnouinceput
Influenced by:

    
    
        TypeScript's type safety
    
        Python's syntax, modules and extensibility
    
        JavaScript's availability
    
        Ruby's loops and blocks
    
        PHP's dedication to server-side
    
        Haskell's immutability
    
        C's speed
    
        NumPy's matrix arithmetics
    
        Perl's regex engine
    

Ehh, they forget to add another:

Will be used for exactly zero real-life production projects.

