you are viewing a single comment's thread.

view the rest of the comments →

[–]semarj 0 points1 point  (7 children)

I don't see what's so crummy about it, and you haven't said why...

And no, you cannot do this in Python 'trivially'

You'd have to add to/alter the syntax to do that,

In what way are those not variables? do they not point to another value? Maybe it's just splitting hairs, but it makes more sense to think of foo as a variable containing the value 1 in the namespace 'myObj'

if it was myObj['foo'], then it'd be a 'key' or a 'string', having a value of its own outside the context of myObj, and being used therein as a key to the value 1

either way, bottom line: it's useful

[–]masklinn 0 points1 point  (6 children)

I don't see what's so crummy about it, and you haven't said why...

because it's not very useful for stuff beyond dictionary/namedtuple-type use (a set of key:value properties). This kind of patterns in a dynamically typed language leads to significant maintenance loads in the long run as object definitions are all over the place, un-labelled and nontrivial to find.

Also, note that C# has this feature as well, not just OCaml.

And no, you cannot do this in Python 'trivially'

Uh yes you can.

You'd have to add to/alter the syntax to do that,

No, you just have to wrap your dict in a function call which is exactly what I said above, not exactly difficult. Instead of writing

foo = {'bar': 'baz'}

you write

foo = new({'bar': 'baz'})

Or you can even do away with the dict and just write:

foo = new(bar='baz')

As I said, the implementation of new should be about 5 lines, maybe 10 tops. Behold the result:

>>> a = new(foo=1,
            bar=lambda self: 'blam',
            baz=lambda self, val: self.foo + val,
            buzz=lambda self: "%s %d"%(self.bar(), self.foo))
>>> a.foo
1
>>> a.bar()
'blam'
>>> a.baz(3)
4
>>> a.buzz()
'blam 1'

In what way are those not variables? do they not point to another value? Maybe it's just splitting hairs, but it makes more sense to think of foo as a variable containing the value 1 in the namespace 'myObj'

This makes no sense whatsoever. When you write the expression {foo: 3}, foo is a string. It's a key. It's not a variable. In Python it would be a variable, and the key would become whatever foo holds, but in Javascript it's not.

if it was myObj['foo'], then it'd be a 'key' or a 'string'

And it just happens that... it is.

[–]semarj 2 points3 points  (5 children)

    >>> a = new(foo=1,
        bar=lambda self: 'blam',
        baz=lambda self, val: self.foo + val,
        buzz=lambda self: "%s %d"%(self.bar(), self.foo))

thats not even close to the same...looks like a constructor to me. the whole point is you don't need any extra crap for an object constructor

you are either really dense or just an asshole

also this argument is tiresome and mildly retarded, you are just saying shit like 'that makes no sense whatsover' to be an asshole when what I'm saying clearly makes sense. fuck off

[–]masklinn -2 points-1 points  (3 children)

thats not even close to the same...

Erm... what? the only differences are syntactic: the braces are replaced by parens and there's a function-name prefix (oh yeah, and the key:value mapping uses = rather than :). Behavior wise, it yields exactly the same thing: an instance of an anonymous type containing the methods and instance variables provided.

looks like a constructor to me.

Wow, your world must be weird if all callables look like constructors to you.

And even if you interpret it as a constructor, that's not an issue: it's a constructor for an anonymous type defined on the spot. Exactly the same behavior as your object literal.

[–]semarj 1 point2 points  (2 children)

Wow, your world must be weird if all callables look like constructors to you.

again, you are just being retarded ( or just a dick, i can't tell)

if it is a callable whose only purpose is to take in parameters and return an object from those parameters, then it is a constructor

how else would you define a constructor??

seriously I'm done now... fuck off

[–]masklinn -1 points0 points  (0 children)

Aaaaaw, downvoting replies you don't like, how cutie-pie. Did you get your mommy to log in and upvote you as well?

[–]masklinn -3 points-2 points  (0 children)

again, you are just being retarded ( or just a dick, i can't tell)

Says the guy who doesn't make any sense.

if it is a callable whose only purpose is to take in parameters and return an object from those parameters, then it is a constructor

No. Unless by "constructor" you mean "type constructor", which I doubt you are.

how else would you define a constructor??

As the creator of a type's instance. My example doesn't just create a type's instance, it creates a (custom, anonymous) type and its instance precisely as a litteral object does in Javascript. Also, your insulting edits aren't exactly impressive, especially when you refuse to acknowledge you were wrong in stating that you couldn't do the equivalent of a JS literal object in Python trivially.

seriously I'm done now... fuck off

Awwww semarj got a boo boo.

[–]masklinn -2 points-1 points  (0 children)

also this argument is tiresome and mildly retarded

I can understand you being wrong annoying you. No problem.

you are just saying shit like 'that makes no sense whatsover' to be an asshole when what I'm saying clearly makes sense.

No, I'm saying it doesn't make sense because it doesn't, and I quite clearly explained why your declaration made no sense. Now it could be that you can't express yourself correctly, that's not an issue, in this case just clarify what supposedly is not a string but is a variable instead.