9 ms·
The Chaos Programming Language
- nerdponx 6y agoWhat'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.
- azhenley 6y agoI 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 6y agoYeah, 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.
- dilippkumar 6y agoFrom 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?
- gnarbarian 6y agoIf it's impossible to write anything you're guaranteed to not have any errors.
- Avshalom 6y agoI mean yes it's either obviously wrong or hyperbole, I assume the second. But I think the idea is that by forcing each branch in a case to be an separate function they are forced to be unit testable.
- a-nikolaev 6y agoBut then any more or less complex code that involves conditions will be spread over multiple functions. Even if that makes it testable, it might become incomprehensible very quickly. Edit: If code needs certain number of conditions, they will be there in this or that form, that cannot be avoided. I would like to see real benefits of their choice in real non-trivial examples.
- disconcision 6y agoI don't think '100%' distributes over commas in this case, especially given the formatting in the original
- curryhoward 6y agoI 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 6y agoI 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 6y agoWPA2 is a formally verified protocol. It lasted 14 years: https://www.krackattacks.com/ https://www.krackattacks.com/. Now it's partially formally verified.
- danielscrubs 6y agoYou 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-vulnerability/ https://galois.com/blog/2017/10/formal-methods-krack-vulnera...
- hyperpallium 6y ago"100%" only qualifies "testable".
- tomc1985 6y agoThat sounds.... chaotic
- jedberg 6y ago> 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?
- Widdershin 6y agoMaybe 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?
- nv-vn 6y agoThis is doing something different though. It first declares a as a num, then assigns it. There's not really a great equivalent in Haskell syntax, but in C: int a = 5; a = 7;
- eyelidlessness 6y agoI 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.
- eyelidlessness 6y agoI guess an argument can be made that forcing a restart of the REPL is a pretty harsh punishment, but I would expect Haskell (of all languages) to at least require some kind of tabula rasa.
- Widdershin 6y agoIf it makes you feel better node doesn't allow you to reassign const declarations in the REPL, which is actually very annoying if you forget about that behaviour and tend to default to writing const.
- fn_esc 6y agono-branching is an interesting concept, but that’s not what “immutable” means. also, why are there 3 synonyms for every single keyword?
- mertyildiran 6y agoThanks 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 6y agoNo 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.
- golergka 6y agoAs 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.
- curryst 6y agoThat doesn't seem possible. A function with no flow control statements has a cyclomatic complexity of 1. I.e. function retVal(x) { return x } has a cyclomatic complexity of 1 because there is 1 path through. Even ignoring that issue, even if the control flow statement is in the return, it still has a cyclomatic complexity of 2. I.e. function isEqual(x, y) { return x == y } still has a cyclomatic complexity of 2, you're just hiding it. The actual logic flow in terms of nodes is ``` if (x == y) { return true } else { return false } ``` It's entirely possible for a single line to have a cyclomatic complexity of more than 1. Ternaries, for example, would have a cyclomatic complexity of 3.
- mertyildiran 6y agoYes, 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 6y agoI'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.
- unnouinceput 6y agoInfluenced 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.
- souenzzo 6y agoPlease 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.
- catlifeonmars 6y agoThe 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.
- smoyer 6y agoCan this be compiled (and minimized) at some point or are we stuck with an interpreter?
- amdelamar 6y agoLooks 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)
- andrewflnr 6y agoCyclomatic 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 6y agoOne might even go so far as to say that the whole program is a function :)
- rafaelvasco 6y agoSeems 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 6y ago> I found some of the language features quite alien. You might even say they are arcane.
- rafaelvasco 6y agoAhaha. Perfect :)
- deleted 6y ago[deleted]
- winstonewert 6y agoDid 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)
- louis8799 6y agoDude you got it wrong, this is actually a joke language.
- progval 6y ago> 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.
- staticassertion 6y agoI 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 6y agoSince 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 6y agoAs 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
- remcob 6y agoCreative 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.
- olodus 6y agoInteresting 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.
- pmontra 6y agoIt'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.
- tohuvavohu 6y agoThe "Hello World" example says to run "hello.kaos" with "$ chaos dev.kaos". Is the renaming from hello.kaos to dev.kaos intentional?
- danielscrubs 6y agoYou 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.
- rurban 6y agoExtremely 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.
- thiht 6y agoHaving 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 6y agoThis 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.
- gitgud 6y ago> 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 6y agoI 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.
- isaiahg 6y agoI 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.