HI all,
After much faffing about on other things, I finally managed to
get the slides up. For anyone interested, they're here:
http://www.mega-nerd.com/erikd/Blog/CodeHacking/fp-tail-js.html
Cheers,
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
Well that's very interesting (I missed the meeting). I had no idea about doing TCO in js -- have to look at that. I'm wading through SICP myself which talks about this stuff -- http://mitpress.mit.edu/sicp/. Sections 1-2-1 and 1-2-2 which I'm going thru are quite relevant in this regard: you learn to do iterations recursively as well as appreciating the power and elegance (and expense) of non-iterative recursion (plus you learn scheme which is a lisp -- reminds me of several comments and relations that Douglas Crockford has made between js and scheme/lisp) Thinking out loud: Am I the only one who thinks it's a small miracle that the browser got a scripting language, much maligned early on, that ended up having lexical scope and closures, higher order and anonymous functions and the ability to create objects (via closures or the "new" keyword)? Can you imagine if we had ended up with vbscript in the browser instead? :) On 30 November 2010 22:13, Erik de Castro Lopo <mle+cl@mega-nerd.com<mle%2Bcl@mega-nerd.com> > wrote: > HI all, > > After much faffing about on other things, I finally managed to > get the slides up. For anyone interested, they're here: > > http://www.mega-nerd.com/erikd/Blog/CodeHacking/fp-tail-js.html > > Cheers, > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ > -- -- Daniel Bush http://daniel-bush.blogspot.com
Daniel Bush wrote: > Thinking out loud: > Am I the only one who thinks it's a small miracle that the browser got a > scripting language, much maligned early on, that ended up having lexical > scope and closures, higher order and anonymous functions and the ability to > create objects (via closures or the "new" keyword)? I heard (but have never been able to confirm) that a very early version of Javascript was actually a cut-down version of scheme. When the author showed it to other people he was told "great idea, but no one is going to want to write scheme". He then changed the syntax to be more C and Java like. Since you mentioned "much maligned" I must say, as some one who loves the real bondage and discipline languages like Ocaml and Haskell, what I saw in the Di-script-ions section of the last meeting really horrified me :-) Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
On 1 December 2010 10:43, Erik de Castro Lopo <mle+cl@mega-nerd.com<mle%2Bcl@mega-nerd.com> > wrote: > Daniel Bush wrote: > > > Thinking out loud: > > Am I the only one who thinks it's a small miracle that the browser got a > > scripting language, much maligned early on, that ended up having lexical > > scope and closures, higher order and anonymous functions and the ability > to > > create objects (via closures or the "new" keyword)? > > I heard (but have never been able to confirm) that a very early version > of Javascript was actually a cut-down version of scheme. When the author > showed it to other people he was told "great idea, but no one is going to > want to write scheme". He then changed the syntax to be more C and Java > like. > > I think you're referring to Brendan Eich. http://weblogs.mozillazine.org/roadmap/archives/2008/04/popularity.html (note: sicp gets mentioned) I don't know if there ever was actual scheme at some point very early in the history, but as D Crockford has said: "javascript is lisp in C's clothing" minus the homoiconicity :) . ( http://www.crockford.com/javascript/javascript.html). > Since you mentioned "much maligned" I must say, as some one who loves > the real bondage and discipline languages like Ocaml and Haskell, what > I saw in the Di-script-ions section of the last meeting really > horrified me :-) > > > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ > -- -- Daniel Bush http://daniel-bush.blogspot.com
I am sorry for that. :) It was a pretty bad portion of the language. There is beauty in the language i promise! I did preface the de-script-ion with 'please never write code like this'. While it is possible to abuse the language to such extremes, people should really think twice about doing it. Also if that horrified you, never look at its typing system. Someone with a love of functional languages would probably give up their keyboard forever if you saw the abuse the type system allows. Jared. On Wed, Dec 1, 2010 at 10:43 AM, Erik de Castro Lopo <mle+cl@mega-nerd.com> wrote: > Daniel Bush wrote: > >> Thinking out loud: >> Am I the only one who thinks it's a small miracle that the browser got a >> scripting language, much maligned early on, that ended up having lexical >> scope and closures, higher order and anonymous functions and the ability to >> create objects (via closures or the "new" keyword)? > > I heard (but have never been able to confirm) that a very early version > of Javascript was actually a cut-down version of scheme. When the author > showed it to other people he was told "great idea, but no one is going to > want to write scheme". He then changed the syntax to be more C and Java > like. > > Since you mentioned "much maligned" I must say, as some one who loves > the real bondage and discipline languages like Ocaml and Haskell, what > I saw in the Di-script-ions section of the last meeting really > horrified me :-) > > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ >
To keep this discussion going, thought i would throw a link to the JS in 10 mins you briefly mentioned in your talk, i read it a week or so before the talk and was pleasantly surprised to see it raised. It is an awesome read for any one interested in Javascript, and some language theory link is here https://github.com/spencertipping/js-in-ten-minutes/ Also highly worth checking out his divergence library if you have a spare hour or so. On Wed, Dec 1, 2010 at 10:49 AM, Jared W <Jared.Wyles@gmail.com> wrote: > I am sorry for that. :) > It was a pretty bad portion of the language. There is beauty in the > language i promise! I did preface the de-script-ion with 'please never > write code like this'. While it is possible to abuse the language to > such extremes, people should really think twice about doing it. > Also if that horrified you, never look at its typing system. Someone > with a love of functional languages would probably give up their > keyboard forever if you saw the abuse the type system allows. > > Jared. > > > On Wed, Dec 1, 2010 at 10:43 AM, Erik de Castro Lopo > <mle+cl@mega-nerd.com> wrote: >> Daniel Bush wrote: >> >>> Thinking out loud: >>> Am I the only one who thinks it's a small miracle that the browser got a >>> scripting language, much maligned early on, that ended up having lexical >>> scope and closures, higher order and anonymous functions and the ability to >>> create objects (via closures or the "new" keyword)? >> >> I heard (but have never been able to confirm) that a very early version >> of Javascript was actually a cut-down version of scheme. When the author >> showed it to other people he was told "great idea, but no one is going to >> want to write scheme". He then changed the syntax to be more C and Java >> like. >> >> Since you mentioned "much maligned" I must say, as some one who loves >> the real bondage and discipline languages like Ocaml and Haskell, what >> I saw in the Di-script-ions section of the last meeting really >> horrified me :-) >> >> Erik >> -- >> ---------------------------------------------------------------------- >> Erik de Castro Lopo >> http://www.mega-nerd.com/ >> >
1. Don’t believe that there nine types in JavaScript. There are six. 2. “never use the == operator” is quite a lame statement. 3. Boxed vs. unboxed chapter is all wrong 4. “Don’t use typeof” is another questionable statement. I don’t like it either, but using constructor property is much worse. Apart from that it’s useful read. Read it with caution. Question everything… including what I wrote here. best, Dmitry On 01/12/2010, at 1:04 PM, Jared W wrote: > To keep this discussion going, thought i would throw a link to the JS > in 10 mins you briefly mentioned in your talk, i read it a week or so > before the talk and was pleasantly surprised to see it raised. It is > an awesome read for any one interested in Javascript, and some > language theory link is here > https://github.com/spencertipping/js-in-ten-minutes/ > > Also highly worth checking out his divergence library if you have a > spare hour or so. > > On Wed, Dec 1, 2010 at 10:49 AM, Jared W <Jared.Wyles@gmail.com> wrote: >> I am sorry for that. :) >> It was a pretty bad portion of the language. There is beauty in the >> language i promise! I did preface the de-script-ion with 'please never >> write code like this'. While it is possible to abuse the language to >> such extremes, people should really think twice about doing it. >> Also if that horrified you, never look at its typing system. Someone >> with a love of functional languages would probably give up their >> keyboard forever if you saw the abuse the type system allows. >> >> Jared. >> >> >> On Wed, Dec 1, 2010 at 10:43 AM, Erik de Castro Lopo >> <mle+cl@mega-nerd.com> wrote: >>> Daniel Bush wrote: >>> >>>> Thinking out loud: >>>> Am I the only one who thinks it's a small miracle that the browser got a >>>> scripting language, much maligned early on, that ended up having lexical >>>> scope and closures, higher order and anonymous functions and the ability to >>>> create objects (via closures or the "new" keyword)? >>> >>> I heard (but have never been able to confirm) that a very early version >>> of Javascript was actually a cut-down version of scheme. When the author >>> showed it to other people he was told "great idea, but no one is going to >>> want to write scheme". He then changed the syntax to be more C and Java >>> like. >>> >>> Since you mentioned "much maligned" I must say, as some one who loves >>> the real bondage and discipline languages like Ocaml and Haskell, what >>> I saw in the Di-script-ions section of the last meeting really >>> horrified me :-) >>> >>> Erik >>> -- >>> ---------------------------------------------------------------------- >>> Erik de Castro Lopo >>> http://www.mega-nerd.com/ >>> >>
Hi Dmitry, You're saying that you disagree but haven't supported your statements with an explanation. I'm genuinely interested :) Cheers, James. On 1 December 2010 21:35, Dmitry Baranovskiy <dmitry@baranovskiy.com> wrote: > 1. Don’t believe that there nine types in JavaScript. There are six. > 2. “never use the == operator” is quite a lame statement. > 3. Boxed vs. unboxed chapter is all wrong > 4. “Don’t use typeof” is another questionable statement. I don’t like it either, but using constructor property is much worse. > > Apart from that it’s useful read. Read it with caution. Question everything… including what I wrote here. > > best, > Dmitry > > > On 01/12/2010, at 1:04 PM, Jared W wrote: > >> To keep this discussion going, thought i would throw a link to the JS >> in 10 mins you briefly mentioned in your talk, i read it a week or so >> before the talk and was pleasantly surprised to see it raised. It is >> an awesome read for any one interested in Javascript, and some >> language theory link is here >> https://github.com/spencertipping/js-in-ten-minutes/ >> >> Also highly worth checking out his divergence library if you have a >> spare hour or so. >> >> On Wed, Dec 1, 2010 at 10:49 AM, Jared W <Jared.Wyles@gmail.com> wrote: >>> I am sorry for that. :) >>> It was a pretty bad portion of the language. There is beauty in the >>> language i promise! I did preface the de-script-ion with 'please never >>> write code like this'. While it is possible to abuse the language to >>> such extremes, people should really think twice about doing it. >>> Also if that horrified you, never look at its typing system. Someone >>> with a love of functional languages would probably give up their >>> keyboard forever if you saw the abuse the type system allows. >>> >>> Jared. >>> >>> >>> On Wed, Dec 1, 2010 at 10:43 AM, Erik de Castro Lopo >>> <mle+cl@mega-nerd.com> wrote: >>>> Daniel Bush wrote: >>>> >>>>> Thinking out loud: >>>>> Am I the only one who thinks it's a small miracle that the browser got a >>>>> scripting language, much maligned early on, that ended up having lexical >>>>> scope and closures, higher order and anonymous functions and the ability to >>>>> create objects (via closures or the "new" keyword)? >>>> >>>> I heard (but have never been able to confirm) that a very early version >>>> of Javascript was actually a cut-down version of scheme. When the author >>>> showed it to other people he was told "great idea, but no one is going to >>>> want to write scheme". He then changed the syntax to be more C and Java >>>> like. >>>> >>>> Since you mentioned "much maligned" I must say, as some one who loves >>>> the real bondage and discipline languages like Ocaml and Haskell, what >>>> I saw in the Di-script-ions section of the last meeting really >>>> horrified me :-) >>>> >>>> Erik >>>> -- >>>> ---------------------------------------------------------------------- >>>> Erik de Castro Lopo >>>> http://www.mega-nerd.com/ >>>> >>> > > -- James
Hi James,
1. Nothing to support. There are six types in JavaScript: null, undefined,
number, string, boolean and object.
2. 4. I wrote a bit about this here:
http://dmitry.baranovskiy.com/post/typeof-and-friends
3. I am going to write a blog post about this, but in short
In JS there are objects and primitives. JS converts values from one type
to other depending what you are doing with it:
var a = "3";
a--;
Here I applied decrement operator to string. It doesn’t make sense, but JS
convert it to number and then apply the operator. After second line a is a
number 2.
Another example:
var a = "3";
a.length
Strings are primitives, they don’t have properties. Dot operator, just
like many others could only be applied to objects. When you trying to
apply it to primitives JS converts them into objects and apply dot
operator to those objects. So, second line is equivalent to:
Object(a).length // or
new String(a).length
Obviously assigning properties to primitives doesn’t work because every
time you ask for property you are dealing with freshly created object.
4. typeof is much faster than anything else, besides it is the only way to
deal with non-existing variables:
if (typeof blah == "undefined") …
Just beware that typeof lies in two cases:
typeof null == "object" // should be "null"
typeof function(){} == "function" // should be "object"
best,
Dmitry
On 01/12/2010, at 11:02 PM, freshtonic@gmail.com wrote:
> Hi Dmitry,
>
> You're saying that you disagree but haven't supported your statements
> with an explanation. I'm genuinely interested :)
>
> Cheers,
>
> James.
>
> On 1 December 2010 21:35, Dmitry Baranovskiy <dmitry@baranovskiy.com> wrote:
>> 1. Don’t believe that there nine types in JavaScript. There are six.
>> 2. “never use the == operator” is quite a lame statement.
>> 3. Boxed vs. unboxed chapter is all wrong
>> 4. “Don’t use typeof” is another questionable statement. I don’t like
it either, but using constructor property is much worse.
>>
>> Apart from that it’s useful read. Read it with caution. Question
everything… including what I wrote here.
>>
>> best,
>> Dmitry
>>
>>
>> On 01/12/2010, at 1:04 PM, Jared W wrote:
>>
>>> To keep this discussion going, thought i would throw a link to the JS
>>> in 10 mins you briefly mentioned in your talk, i read it a week or so
>>> before the talk and was pleasantly surprised to see it raised. It is
>>> an awesome read for any one interested in Javascript, and some
>>> language theory link is here
>>> https://github.com/spencertipping/js-in-ten-minutes/
>>>
>>> Also highly worth checking out his divergence library if you have a
>>> spare hour or so.
>>>
>>> On Wed, Dec 1, 2010 at 10:49 AM, Jared W <Jared.Wyles@gmail.com> wrote:
>>>> I am sorry for that. :)
>>>> It was a pretty bad portion of the language. There is beauty in the
>>>> language i promise! I did preface the de-script-ion with 'please never
>>>> write code like this'. While it is possible to abuse the language to
>>>> such extremes, people should really think twice about doing it.
>>>> Also if that horrified you, never look at its typing system. Someone
>>>> with a love of functional languages would probably give up their
>>>> keyboard forever if you saw the abuse the type system allows.
>>>>
>>>> Jared.
>>>>
>>>>
>>>> On Wed, Dec 1, 2010 at 10:43 AM, Erik de Castro Lopo
>>>> <mle+cl@mega-nerd.com> wrote:
>>>>> Daniel Bush wrote:
>>>>>
>>>>>> Thinking out loud:
>>>>>> Am I the only one who thinks it's a small miracle that the browser got a
>>>>>> scripting language, much maligned early on, that ended up having lexical
>>>>>> scope and closures, higher order and anonymous functions and the ability to
>>>>>> create objects (via closures or the "new" keyword)?
>>>>>
>>>>> I heard (but have never been able to confirm) that a very early version
>>>>> of Javascript was actually a cut-down version of scheme. When the author
>>>>> showed it to other people he was told "great idea, but no one is going to
>>>>> want to write scheme". He then changed the syntax to be more C and Java
>>>>> like.
>>>>>
>>>>> Since you mentioned "much maligned" I must say, as some one who loves
>>>>> the real bondage and discipline languages like Ocaml and Haskell, what
>>>>> I saw in the Di-script-ions section of the last meeting really
>>>>> horrified me :-)
>>>>>
>>>>> Erik
>>>>> --
>>>>> ----------------------------------------------------------------------
>>>>> Erik de Castro Lopo
>>>>> http://www.mega-nerd.com/
>>>>>
>>>>
>>
>>
>
>
>
> --
> James