HNHacker News
TopNewBestAskShowJobs

PySlice

37 karma · joined February 16, 2013

submissionscomments
PySlice··on Not Lisp again (2009)
I read more about Lisp than I program in it, and I feel just like you about the language.

Everything looks the same. Some time ago I read that Common Lisp had multiple return values. I was expecting something like Lua, where a function like this:

function fn() return 1, 2, 3 end

Is called like this:

a, b, c = fn()

But in Lisp, it's just the same old

(some-magic-words-here (other-things) (other-things))

Could I have some commas and equals signs to separate things at least? :-(

Then I heard various Lisps have classes, structs, objects and what not. Does it look like this?

{ name: value, name: value }

Or this?

class Name { Type name; Type name; }

No...

It looks like this:

(def-something ((something-here)) (something-else) (((something-else-2))))

If you are lucky you have a few :keywords or &keywords so your eyes have something to hang onto. Other than that, everything looks so... positional, and a closing parenthesis could mean anything from the end of a simple expression like (+ 1 1) or the end of the declarative part and the start of the executable part of a complex structure.

You don't even need to go that far to find these problems: just look at:

(let ((new-var-2 value) (new-var-2 value)) (some-code-here))

(if (condition) (runs-if-true) (runs-if-false))

You'd better use a very consistent indentation, because there is almost no visual separation between the "runs-if-true" and "runs-if-false"!

PySlice··on Not Lisp again (2009)
I like the fact that you can substitute a more complex expression anywhere, even in the first position (the function to be called), but everything looks so similar that it's hard to see what's going on. I read more code than I write (I like to read about programming languages) and this:

((lambda (x y) (+ x y)) 3 4)

looks much harder to read than this:

(function(x, y) return x+y end)(3, 4).

In the Lua version, you can easily skim the code: here is a function (rather than a Greek letter), the parameters are inside parenthesis and separated by commas, the body comes next until the "end" keyword, it produces (returns) a value and then you pass the parameters (inside parenthesis and separated by commas again) to the function that was just created.

In the Scheme version, how am I supposed to know where this lambda ends other than counting parenthesis and having a lot of practice to recognize that (....... thing thing) is a function call where the function is more than a single name?

Similarly this:

(define (fn x) (lambda (a) (+ a x)))

IMHO looks much harder to read than this:

function fn(x) return function(a) return a+x end end

The second one is much clearer: "return function", you are returning a closure to the caller. The Scheme one makes me think: a function, another function, parenthesis, an expression, then it ends abruptly and I don't know what the hell the code supposed to do. Again, I CAN read that code in Scheme, but only after learning the core concepts in Lua.

PySlice··on Writing Web Applications in Go
> If you already know F#, then Scala is a much simpler Well, F# does seem to have a lot of "bolted-on" features, but Scala always gives the impression that things "come out of nowhere", e.g. a simple underscore turns the whole expression into a lambda! It looks neat, but I will need some practice to get used to things like this. But, as I said, this is just a superficial analysis, some thing we can only learn after some practicing.

> Not sure what you mean with that. Braces, parenthesis, dots, semicolons, and IIRC you can use the arrow => without anything on its left side.

> The method is either defined on the type of the left, or added by an conversion from that type. That's it.

Unless it ends with a colon, right?

> Method calls with one argument can leave out dot and parentheses

That's somewhat simpler than I expected. I thought it was something Perl-like or Ruby-like (where obj.method + 1 is different from obj.method +1). There should be some way to get a reference to a method without calling it, that I still haven't learnt.

> If a method has a side effect, you define and call it with parentheses, otherwise you leave them out

Not sure I understand this. Is this the preferred coding style or something enforced by the compiler?

> I hope that helps a bit! Yes, it helped! Thanks!

PySlice··on Lua: Good, bad, and ugly parts
As long as (0) and (not 0) are opposites; and (1) and (not 1) are opposites, there is nothing wrong, inconsistent or surprising.

But I think I see what you are trying to say. You want the == operator to coerce its operands to the same type before comparing (like JavaScript's == operator), but Lua's == operator doesn't do that, it simply compares. And that's why other languages need an === operator and Lua does not.

(JavaScript, by the way is the inconsistent one in this regard: the == operator does coerce its operands, but if(something == true) doesn't do the same thing as if(something). Try it with an empty array)

PySlice··on Writing Web Applications in Go
I have not written my first Go (or Scala) program yet, but I have written some F# code and loved the language (and the fact that everything is an expression too). It does have som complex features, and special syntax appears very often, but after reading just a bit of documentation, I can easily understand the core concepts and syntax.

On the other hand, Scala gives me a completely different feeling: when reading the docs and samples, I often ask myself:

How can I mentally parse this?

It's nice that I can abbreviate some common constructs (when writing), but when reading code, how can I tell which concepts are being used? How do I look up these operators when they could come from anywhere (global, first operand, second operand, implicit conversion, etc.)

How do I know when parentheses, dots, curly braces, are mandatory or optional? Could the compiler misunderstand me in complex situations? Where does this construct really end if so many things are optional? At least F# uses indentation, so I know the compiler will warn me if I wrote something that is not quite right according to the precedence rules.

There are too many implicit things going on, how do I know which meaning of _ (underscore) is meant here?

PySlice··on Learn Python
A desktop GUI in Python? Or a GUI in a web app? If you mean the former, have you tried wxPython? It comes with a huge interactive library of samples, where you can see the code and the resulting interface just by switching tabs.
PySlice··on Why We Hate Ruby
Those perlisms suck. Perl was a nice experiment in expressiveness and succintness, now that we know better what works and what doesn't, we shouldn't copy it anymore. Maybe something was different in the 90s?
PySlice··on A nice, little known C feature: Static array indices in parameter declarations
That looks nice, but I think it could be simply void bar(int myArray[10]), since C effectively ignores the number inside the first pair of brackets in a parameter list, they could have added some meaning to it. No need for another meaning for "static"
PySlice··on A nice, little known C feature: Static array indices in parameter declarations
Why do many features added to C after the first standard have to be quirky and slightly incompatible (with C++, with existing implementations, etc.) like this?

Other examples are inline (different from C++, makes use of weird combinations with static and extern) and tgmath (compiler magic inaccessible to user-defined functions until C11).

They also seem to __barely__ improve the language without ever being "cool" or "interesting".

At least C++ has some standard data structures...

PS: Even Python has binary literals, while they were deemed "not useful enough" for C.

PySlice··on The Perl Renaissance
That's the funny part :-)
PySlice··on The Perl Renaissance
Python significant white space is just like nudism. At first you think something essential is missing (clothes, curly braces), then you notice that it wasn't really needed at all, and everything becomes freer and simpler.
← PreviousPage 2 of 2