Live data from Hacker News

The Chaos Programming Language

chaos-lang.org

51–60 of 87 posts

Re: The Chaos Programming Language

#51

Earlier quoted context omitted.

Ah, I did not dive that deep. Now I am curious what the impact of deep copies on performance is, and if the language employs any clever optimizations to improve performance.

I don't see how you can reliably deep copy any user defined class either.

There are none, at least in the familiar OOP sense:

> Chaos language is not object-oriented. So everything is done by functions and data types.

Re: The Chaos Programming Language

#52
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.

Re: The Chaos Programming Language

#53
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.

Re: The Chaos Programming Language

#54

Earlier quoted context omitted.

Reassignment is mutation. It's really not... on a spectrum of mutability. JavaScript const objects allowing mutation of internal data is vaguely on that spectrum, even though it's misleading and confusing. Literally reassigning a variable isn't even up for debate.

Everyone says strings in java are immutable, yet you can still re-assign to string variables. It really is up for debate.

Java strings are immutable. Java variables with a string type are not. It's really not up for debate. You can't mutate a string in Java (you can in Ruby), but you can mutate a string variable by reassigning it.

Re: The Chaos Programming Language

#55
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.

Re: The Chaos Programming Language

#56
post #4

> 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?

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.

That's standard behavior for object oriented languages. A different example with functions:

  function add(x, y) {
    return x + y
  } 
  a = 5
  add(a, 1)
  print(a)
A language printing 6 is pass by reference. A language printing 5 is pass by value. Both would print 6 for this code

  a = add(a, 1)
  print(a)
However a language like Erlang would end with an error when trying to reassign a new value to a.

Re: The Chaos Programming Language

#57
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.

Re: The Chaos Programming Language

#58

Earlier quoted context omitted.

Maybe the REPL behaves different than the interpreter? Haskell REPLs tend to work the same way. GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help Prelude> a = 5 Prelude> a = 7 Prelude> print a 7 But yeah, it doesn't seem like there's any support for first class functions either, so perhaps just a bit too much creative license in marketing?

I have never worked with Haskell but admire it from afar, and I'm honestly astonished that the REPL works this way. I would assume this would error at the compiler for a normal program, and that the REPL runtime would enforce the same constraints.

You're just shadowing the previous binding with a new one, not actually mutating anything[1]:

   λ>  let foo = 1
   λ>  let foo = 2
   λ>  foo
     => 2
could be rewritten[2] as

   λ> let foo = 1 in ( let foo = 2 in foo )
     => 2
which makes the semantics more clear.

This idiom is also quite common in Clojure, another famously immutable-first language:

  (let [foo 1
        foo 2]
    foo)
  ;; => 2
In my opinion (predominantly informed by my experience with those two languages contrasted with the usual suspects from mutable-OOP-land), the benefit of immutability isn't what's happening in your own local scope, since it's typically quite easy to track what your immediate context is doing to a variable. Instead, it's the language-enforced promise that the only changes to local values can come from local actions: your function and method calls can never have spooky side effects, nor can other threads if you're in some hellish concurrent environment.

In this light, Chaos's apparent syntactic sugar of

  a[15] = 44
to mean (using some hand-wavey pidgin)

  a = a.updateAt(15,44)
seems quite reasonable and fully in the spirit of immutability as a meaningful language feature.

[1] In my scratchwork project, my repl actually yells at me with an annoying warning about this:

  :8:5-7: warning: [-Wname-shadowing]
      This binding for ‘foo’ shadows the existing binding
        defined at :6:5
[2] I believe that the haskell repl actually functions like a do-block, so the pedantically correct desugaring possibly involves lambdas and bind, but that's not really an interesting distinction here IMO and makes the example less clear.

Re: The Chaos Programming Language

#59

From 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.…

That sounds.... chaotic

Re: The Chaos Programming Language

#60

Earlier quoted context omitted.

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 a…

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.

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.

Post reply on HN