News for hackers. Stuff that matters.
Re:How to store your app's entire state in the url by a_c on Monday January 09, 2023 @02:49PM (#34315051)
OT, we used to joke about LISP source code contains mostly brackets. Nowadays we literally store, transform and pass around willy nillily
Re:How to store your app's entire state in the url by hk__2 on Monday January 09, 2023 @06:01PM (#34317811)
Speaking about LISP and state in the URL, this is how OVH stores the state when you buy a domain from them:

    https://www.ovh.com/fr/order/webcloud/?#/webCloud/domain/options?selection=~(domains~(list~(~(name~'somethinghn.com))~options~(~'dnssec)))
Re:How to store your app's entire state in the url by TeMPOraL on Monday January 09, 2023 @07:23PM (#34318539)
That's Clojure's EDN encoded for ClojureScript isn't it? I recognize this syntax from briefly working on a CLJ/CLJS app.
Re:How to store your app's entire state in the url by bsima on Tuesday January 10, 2023 @07:55AM (#34324106)
Nope, edn uses square brackets and doesn't have a `list` keyword. This is some custom representation.

Probably written in Common Lisp? Based on some quick searching I found this reference https://docs.ovh.com/us/en/web-paas/languages-lisp/

Re:How to store your app's entire state in the url by mattpallissard on Tuesday January 10, 2023 @11:48AM (#34327626)
Or it could just be that s expressions are easy to parse.
Re:How to store your app's entire state in the url by TeMPOraL on Monday January 09, 2023 @07:26PM (#34318567)
I found that joke funny until I realized that, if you sum the count of round, square, angle and curly braces together, your typical piece of C++ or Java code has more brackets than equivalent piece of Lisp code...
Re:How to store your app's entire state in the url by spullara on Monday January 09, 2023 @08:40PM (#34319200)
Right, but having them all be the same is what people are joking about :) Although I might check the lisp/clojure vs java code on techempower or another rosetta stone like example.
Re:How to store your app's entire state in the url by moring on Tuesday January 10, 2023 @01:46AM (#34321358)
That, and the usual style of stacking all closing parentheses together at the end of the last line of a sub-expression / statement / whatever. People sometimes do this in Java and it's just as unreadable.
Re:How to store your app's entire state in the url by User23 on Tuesday January 10, 2023 @10:33AM (#34326333)
You read it by indentation not by counting parentheses.
Re:How to store your app's entire state in the url by WorldMaker on Tuesday January 10, 2023 @03:43PM (#34331196)
It's still very easy to make mistakes reading it that way. If you are reading it by indentation anyway you may as well use a parser that closes parentheses for you at indentation changes. (Like the ML family and Haskell and Python all decided to do.)
Re:How to store your app's entire state in the url by User23 on Tuesday January 10, 2023 @04:40PM (#34331904)
* * *
Re:How to store your app's entire state in the url by NavinF on Tuesday January 10, 2023 @02:55AM (#34321812)
Well yeah that's a major reason why most programmers hate LISP syntax. It uses a parentheses for everything even though every keyboard has round, square, angle and curly braces.
Re:How to store your app's entire state in the url by TeMPOraL on Tuesday January 10, 2023 @03:32AM (#34322034)
I somehow doubt it. I tutored quite a few people of all ages who started to learn programming, mostly C, C++ and Java - they all initially have been mostly confused by the different kinds of brackets. They quickly understood where the brackets go (scopes/blocks, function calls, array declarations and access, etc.), but took some time to internalize which bracket type is used in which context.

I suspect the main reason programmers dislike Lisp syntax is that they try or see an example of some basic arithmetics, get surprised by the prefix notation that's so "unnatural" compared to the "obvious" infix notation they learned in primary school, and write off the entire language as weird, not noticing the fact that infix math is an exception in programming languages, as otherwise almost all code they write in any other language is in prefix notation too, just with a parenthesis shifted to the left.

A somewhat mind-blowing observation to some people:

  (foo (bar baz quux))
  
  foo(bar(baz, quux));
The two lines above are both in prefix notation. You can go from the first to the second one by a) shifting each left paren by one token to the right, and b) adding commas between whitespace-separated tokens.
Re:How to store your app's entire state in the url by xmprt on Tuesday January 10, 2023 @03:58AM (#34322175)
I suppose beginner programmers might find all the different kinds of brackets in C++ confusing but after some experience, it helps a lot with readability. If I see `a[1]` then I know that `a` is probably an array. If I see `a(1)` then I know that `a` is probably a function. You could make the argument that those are terrible names for variables and methods and you'd be correct, but every small bit of context helps.
Re:How to store your app's entire state in the url by spullara on Sunday January 15, 2023 @10:26PM (#34396459)
Like most of the verbosity in those languages it benefits the reader more than the writer.
Re:How to store your app's entire state in the url by moonchrome on Tuesday January 10, 2023 @07:36AM (#34323901)
Clojure uses [] and {}, eg. :

  (defn fib [x, n]
    (if (< (count x) n) 
      (fib (conj x (+ (last x) (nth x (- (count x) 2)))) n)
      x))
Re:How to store your app's entire state in the url by reaperducer on Monday January 09, 2023 @08:40PM (#34319198)
we used to joke about LISP source code contains mostly brackets.

There was a programming language in the 1970's called SAM76 that didn't care how many closing parentheses you had, as long as it was more than the number of opening parentheses.

So, something like this was perfectly valid:

  a(1+r(em(2)))))))))))))))))))
Re:How to store your app's entire state in the url by bboygravity on Monday January 09, 2023 @10:15PM (#34320066)
That's genious IMO. Making sure the amount of opening and closing parantheses is equal is annoying and unnecesary.

It screams "trust me all good with the closing parantheses".

Re:How to store your app's entire state in the url by andreareina on Tuesday January 10, 2023 @12:12AM (#34320798)
paredit and rainbow parens makes it a non-issue for me.
Re:How to store your app's entire state in the url by paledot on Tuesday January 10, 2023 @12:18AM (#34320829)
I disagree. I would say when I get an unbalanced paren compiler error, it's more common for the omission to not be at the end of the line. Having the compiler silently swallow the error would lead to serious bugs very quickly.
Re:How to store your app's entire state in the url by tonmoy on Tuesday January 10, 2023 @12:55AM (#34321041)
What if I wanted to copy that expression and use is as part of a different expression?
Re:How to store your app's entire state in the url by NavinF on Tuesday January 10, 2023 @03:02AM (#34321854)
Interactive prompts already do that. Eg if you google "2+2)*3" it will correctly print "12". This effectively lets you append operations to an expression without editing both sides.

On the other hand, auto closing parentheses in code is a terrible idea for obvious reasons. There are only like 7 languages used in industry and they all have excellent tooling that integrates with your editor to eliminate issues like this.

Re:How to store your app's entire state in the url by ajuc on Tuesday January 10, 2023 @03:16AM (#34321935)

    if ((v1.x()-v2.x())*(v1.x()-v2.x())+(v1.y()-v2.y())*(v1.y())-v2.y())+(v1.z()-v2.z())*(v1.z()-v2.z()) > distance*distance) {
        // collision
    }
Would you like this to fail to compile? Or would you prefer it to silently return the wrong value?
Re:How to store your app's entire state in the url by matthewmacleod on Tuesday January 10, 2023 @04:18AM (#34322286)
I'd prefer the compiler file an HR complaint against the author.
Re:How to store your app's entire state in the url by wstuartcl on Wednesday January 11, 2023 @12:25PM (#34341203)
if collisioncheck(v1,v2, distance) { // collision }

where you have defined an actually readable equivalent inside of collisioncheck would be my prerogative... I also agree paren matching failures should error, but your example is NOT why.

Re:How to store your app's entire state in the url by lIl-IIIl on Tuesday January 10, 2023 @02:24AM (#34321606)
Relevant xkcd: https://xkcd.com/859