Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sapozhnik
Jan 2, 2005

Nap Ghost

Space Whale posted:

I finally had a reason to do more than glue some JS. I tried to overload a method.

lolnope gotta null check (or falsy check) parameters

loving poo poo this language

you can't overload methods in javascript unless you fake it with varargs though?

or do you mean override

cuz those aren't the same thing :smug:

Adbot
ADBOT LOVES YOU

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
javascript's object system is so bad

Sapozhnik
Jan 2, 2005

Nap Ghost

Symbolic Butt posted:

javascript's object system is so bad

it's kinda appealing-despite-my-better-judgement if you don't call them objects and just call them associative arrays instead and also don't use prototype inheritance because otherwise you'll go mad trying to figure out what "this" means in any given context and then dehumanize yourself and face to closure hell. like doing single-threaded async io in javascript is probably legit easier than any other curly brace language as a result which is why node.js is a thing i suppose

note that i'm not necessarily using "closure hell" perjoratively here

brap
Aug 23, 2004

Grimey Drawer
the way I look at it is, method overloading depends on whether the types and number of parameters are part of the definition of the function

javascript lets you call functions with as many or as few arguments as you want so there's no overloading like you would have in java or c#. you just need to handle the different sets of parameters you expect at the top of your function.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Mr Dog posted:

don't use prototype inheritance because otherwise you'll go mad trying to figure out what "this" means in any given context and then dehumanize yourself and face to closure hell.

hmm? what's confusing about that? this is always the object on which the method was called, regardless of where in the prototype chain the method was found. this is how it works in classical inheritance as well, really: this doesn't change identity or dynamic type just because you're in an inherited method body.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Subjunctive posted:

hmm? what's confusing about that? this is always the object on which the method was called, regardless of where in the prototype chain the method was found. this is how it works in classical inheritance as well, really: this doesn't change identity or dynamic type just because you're in an inherited method body.

no im pretty sure sometimes self is super and sometimes its not

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Snapchat A Titty posted:

no im pretty sure sometimes self is super and sometimes its not

you should file that bug, then. if that were the case then setting properties on this-cum-super would affect all instances, for starters.

perhaps you're referring to the fact that this isn't captured by a closure, but it instead dynamically determined at invocation time (defaulting to the global object if it's called outside of a method-call expression)?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Subjunctive posted:

you should file that bug, then. if that were the case then setting properties on this-cum-super would affect all instances, for starters.

perhaps you're referring to the fact that this isn't captured by a closure, but it instead dynamically determined at invocation time (defaulting to the global object if it's called outside of a method-call expression)?

soz im joking

i meant to say i cant really imagine a situation where this/self does not refer to the instance currently executing the method. this is always this. if its not this, its gotta be some esolang where the closure moves step by step :aaaaa:

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

Subjunctive posted:

hmm? what's confusing about that? this is always the object on which the method was called, regardless of where in the prototype chain the method was found. this is how it works in classical inheritance as well, really: this doesn't change identity or dynamic type just because you're in an inherited method body.

except for call and apply and junk like that.

comedyblissoption
Mar 15, 2006

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
doug crockford is one of those fundamentalists who think the ++ operator is satan reincarnated

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



i guess props for wearing a jacquet but also not for what looks like green or brown corduroys?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



he looks like an angry ridley scott emerging from a swamp

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

I stopped writing javascript

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

i saw some talk where he mentioned those points, but he never elaborated on them

Notorious b.s.d.
Jan 25, 2003

by Reene

Suspicious Dish posted:

doug crockford is one of those fundamentalists who think the ++ operator is satan reincarnated

confronted by a vile and worldly creature like javascript, the ascetic approach is the reasonable choice

with enough self-denial there might be a usable language under there somewhere

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Wheany posted:

i saw some talk where he mentioned those points, but he never elaborated on them

yeah, that was the exact moment that I realized how flaky Crockford is

I mean, before that there was jslint and dec64 but I guess I'm just slow

distortion park
Apr 25, 2011


Suspicious Dish posted:

doug crockford is one of those fundamentalists who think the ++ operator is satan reincarnated

tbh using x++ or ++x as a function argument is pretty bad

distortion park
Apr 25, 2011


if ++ didn;t already exist and someone suggested it we'd all be mocking them mercilessly

Soricidus
Oct 21, 2010
freedom-hating statist shill

pointsofdata posted:

if ++ didn;t already exist and someone suggested it we'd all be mocking them mercilessly

nah one sight of while (*a++ = *b++); and we'd all realise how perfect an operator it is and add it to every language forever

crazypenguin
Mar 9, 2005
nothing witty here, move along

pointsofdata posted:

if ++ didn;t already exist and someone suggested it we'd all be mocking them mercilessly

idk, I might endorse the idea as a statement, but not as an expression.

i kind also feel the same way about = and its friends.

suffix
Jul 27, 2013

Wheeee!

pointsofdata posted:

if ++ didn;t already exist and someone suggested it we'd all be mocking them mercilessly

http://blogs.msdn.com/b/oldnewthing/archive/2015/05/25/10616865.aspx

AWWNAW
Dec 30, 2008

wow that is stupid

Serenade
Nov 5, 2011

"I should really learn to fucking read"
++ has side effects, is literally hitler

MrMoo
Sep 14, 2000

An article like that is a two-edged sword, the visual studio team are dumb enough to implement retarded new ideas. So many comments.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

MrMoo posted:

An article like that is a two-edged sword, the visual studio team are dumb enough to implement retarded new ideas. So many comments.

it already exists everywhere :ssh:

pseudorandom name
May 6, 2007

shut up, let them keep springing the trap

qntm
Jun 17, 2009

Notorious b.s.d. posted:

with enough self-denial there might be a usable language under there somewhere

true of every language I've used

Soricidus
Oct 21, 2010
freedom-hating statist shill

MrMoo posted:

An article like that is a two-edged sword, the visual studio team are dumb enough to implement retarded new ideas. So many comments.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

MrMoo posted:

An article like that is a two-edged sword, the visual studio team are dumb enough to implement retarded new ideas. So many comments.

:allears:

Lime
Jul 20, 2004

Wheany posted:

i saw some talk where he mentioned those points, but he never elaborated on them

i found a different talk looking for the first one and anyway this slide explains most of the points



no this because an object's methods are all defined in a closure with its members so they don't need to use this

no object.create or new or prototypes at all because every object is flat and has its own copy of every function in its inheritance chain

i don't know what no null is about, i watched five minutes of this talk and thats enough, but since you can delete keys from objects anywhere youd need it i'd guess he probably just does that

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
that is the worst outfit and facial hair i've seen in a while

brap
Aug 23, 2004

Grimey Drawer
douglas crockford is kind of a clown but watching the talk helps you understand javascript if you didn't before I guess

hopefully part of what you understand in the end is that prototypal inheritance sucks and if you must write javascript then just mash values into objects until you get the result you want

passing around anonymous functions in javascript works nicely but it's basically the only thing about the language that works so you get callbacks inside callbacks inside callbacks endlessly to do anything

he also came up with DEC64 lol http://dec64.com

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
why does crockford like flat objects

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
maybe because then you don't have to do hasOwnProperty?

Soricidus
Oct 21, 2010
freedom-hating statist shill
that's not a reason for liking flat objects. it's a reason for hating [the alternatives available in] javascript.

qntm
Jun 17, 2009
closures are a poor man's objects and vice versa

comedyblissoption
Mar 15, 2006

Lime posted:

i found a different talk looking for the first one and anyway this slide explains most of the points



no this because an object's methods are all defined in a closure with its members so they don't need to use this

no object.create or new or prototypes at all because every object is flat and has its own copy of every function in its inheritance chain

i don't know what no null is about, i watched five minutes of this talk and thats enough, but since you can delete keys from objects anywhere youd need it i'd guess he probably just does that
javascript's prototype and constructor bullshit and janitoring the 'this' pointer are such garbage and have so many unnecessary unintuitive pitfalls that you really should follow crockford's advice here

the 'no null' thing is just being consistent in using undefined over null when you can. a bunch of libraries you use are gonna give you null so you can't really avoid it. this point doesn't really matter imo.

the 'avoid falsiness' thing is to use the === operator almost always and avoid automatic coercion, preferably w/ some linting program.

when you use the subset of javascript that crockford is advocating, javascript becomes a lot more like scheme. except it's statement-based instead of expression based which sucks. and it doesn't have sane metaprogramming. and uh it has a lack of a good set of number primitives. and it has a stupid notion of scope. and it doesn't support recursion as well. but yeah pretty similar.

comedyblissoption
Mar 15, 2006

also dont take that as a defense of javascript

javascript is truly a really garbage language and it's such garbage you should avoid most of its 'features' and use a very limited subset of it

Adbot
ADBOT LOVES YOU

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Crystal seems like a nice language. I just can't believe they went through all the effort to make a better ruby and didn't remove 'unless'

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply