Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34459 > unrolled thread

Object oriented programming

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2018-01-05 10:25 -0800
Last post2018-01-09 13:19 +0100
Articles 20 on this page of 61 — 10 participants

Back to article view | Back to comp.lang.javascript


Contents

  Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-05 10:25 -0800
    Re: Object oriented programming "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-05 11:51 -0800
      Re: Object oriented programming Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-05 23:47 +0100
        Re: Object oriented programming "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-05 15:15 -0800
          Re: Object oriented programming Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-08 03:08 +0100
      Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-05 15:09 -0800
        Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-05 15:21 -0800
          Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-05 15:27 -0800
    Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-05 12:09 -0800
      Re: Object oriented programming "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-05 13:01 -0800
        Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-05 14:38 -0800
          Re: Object oriented programming "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-05 15:29 -0800
            Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-05 15:49 -0800
              Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 02:23 -0800
                Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-06 03:25 -0800
                  Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 03:39 -0800
                    Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-06 04:24 -0800
                      Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 05:26 -0800
                        Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 05:28 -0800
                          Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 05:34 -0800
                            Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 06:08 -0800
                              Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 06:27 -0800
                                Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 06:36 -0800
                                  Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 07:34 -0800
                                  Re: Object oriented programming "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-06 09:56 -0800
                  Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-06 14:21 +0000
                  Re: Object oriented programming Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-01-06 17:42 +0000
                    Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-06 11:47 -0800
                      Re: Object oriented programming "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-06 22:11 +0100
                        Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-06 13:28 -0800
                          Re: Object oriented programming "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-07 12:40 +0100
                            Re: Object oriented programming "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-01-07 13:01 +0100
                              Re: Object oriented programming "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-07 19:43 +0100
                                Re: Object oriented programming "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-01-07 20:33 +0100
                            Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-07 08:30 -0800
                      Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-07 14:05 +0000
                        Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-07 08:33 -0800
                          Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-08 09:46 +0000
                            Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-08 03:45 -0800
                Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-06 03:39 -0800
                  Re: Object oriented programming Julio Di Egidio <julio@diegidio.name> - 2018-01-06 04:24 -0800
                Re: Object oriented programming bit-naughty@hotmail.com - 2018-01-12 22:57 -0800
                  Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-13 13:27 +0000
                    Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-13 08:24 -0800
        Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-06 14:10 +0000
          Re: Object oriented programming "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-06 23:54 -0800
            Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-07 14:13 +0000
              Re: Object oriented programming "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-07 15:26 +0100
                Re: Object oriented programming John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-08 09:39 +0000
                  Re: Object oriented programming "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-09 00:12 +0100
                    Re: Object oriented programming Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-09 02:45 +0100
                      Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-08 21:34 -0800
                        Re: Object oriented programming Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-09 12:52 +0100
                          Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-09 04:41 -0800
                            Re: Object oriented programming Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-09 15:50 +0100
                              Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-09 07:31 -0800
                                Re: Object oriented programming "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-01-10 15:03 -0800
                                  Re: Object oriented programming "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-01-10 15:04 -0800
                                  Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-11 02:06 -0800
                              Re: Object oriented programming Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-09 09:50 -0800
                      Re: Object oriented programming "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-01-09 13:19 +0100

Page 1 of 4  [1] 2 3 4  Next page →


#34459 — Object oriented programming

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-05 10:25 -0800
SubjectObject oriented programming
Message-ID<3c2333ff-00fe-4087-ab49-f52d0546b29b@googlegroups.com>
If one where to buy a single book, that covers most aspects of object oriented programming from scratch "using Javascript".

Which book to buy.

I can see the use of object oriented programming. 
For example i think i would like a midi track object, but how do you set boundaries for an object. For example that tracks can not use same channel and same out port? As i understand it an object have methods for its variables/"attributes?".

But rules for how they can be instantiated, can object oriended programming also handle such. Because that seem almost AI like, so i guess some external mechanism must check so the objects attributes do not collide?

[toc] | [next] | [standalone]


#34460

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2018-01-05 11:51 -0800
Message-ID<9408a4ea-8633-46dd-bc42-43da13cafb87@googlegroups.com>
In reply to#34459
On Friday, January 5, 2018 at 12:25:50 PM UTC-6, Jonas Thörnvall wrote:
> If one where to buy a single book, that covers most aspects of object oriented programming from scratch "using Javascript".
> 
> Which book to buy.
> 
> I can see the use of object oriented programming. 
> For example i think i would like a midi track object, but how do you set boundaries for an object. For example that tracks can not use same channel and same out port? As i understand it an object have methods for its variables/"attributes?".
> 
> But rules for how they can be instantiated, can object oriended programming also handle such. Because that seem almost AI like, so i guess some external mechanism must check so the objects attributes do not collide?


I would say, drop the requirement of it being in JavaScript.

Perhaps the best beginners book on the feeling of OOP is: "A little Java, A Few Patterns" by Felleisen and Friedman.

<https://www.amazon.com/Little-Java-Few-Patterns-Press-ebook/dp/B004GCK2MO/ref=sr_1_1?ie=UTF8&qid=1515180547&sr=8-1&keywords=A+little+Java%2C+a+few+patterns>

It's also less than 200 pages in length. 

Afterwards, follow the style of that book and try to write some basic data structures and algorithms in it. 

An example of the feel:

<script>
abstract class List<T>  {
    abstract append(value: T): List<T>
    abstract concat(list: List<T>): List<T>
    abstract length(): number
    abstract isEmpty(): boolean
    abstract toString(): string
    //etc
}
class Nil<T> extends List<T> {
    append(value: T): List<T> { return new Cons(value, this); }
    concat(list: List<T>): List<T> { return list.isEmpty() ? this : list }
    length(): number { return 0 }
    isEmpty(): boolean { return true }
    toString(): string { return "[]" }
 }
class Cons<T> {
    constructor(readonly head: T, readonly tail: List<T>) { }
    append(value: T): List<T> { return new Cons(this.head, this.tail.append(value)) }
    concat(list: List<T>): List<T> {
        return list.isEmpty() ? this : new Cons(this.head,this.tail.concat(list))
    }
    length(): number { return 1 + this.tail.length() }
    isEmpty(): boolean { return false }
    toString(): string { return `${this.head}::${this.tail}` }
}

var xs: List<number> = new Cons(1, new Cons(2, new Cons(3, new Nil())))
var ys: List<number> = new Nil().append(4).append(5).append(6)
var zs: List<number> = xs.concat(ys)

console.log(zs.toString()) // 1::2::3::4::5::6::[]
</script>

[toc] | [prev] | [next] | [standalone]


#34464

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2018-01-05 23:47 +0100
Message-ID<1930796.tM4inqfQ5m@PointedEars.de>
In reply to#34460
Michael Haufe (TNO) wrote:

> On Friday, January 5, 2018 at 12:25:50 PM UTC-6, Jonas Thörnvall wrote:
>> For example i think i would like a midi track object, but how do you set
>> boundaries for an object. For example that tracks can not use same
>> channel and same out port? As i understand it an object have methods for
>> its variables/"attributes?".

Yes.
 
>> But rules for how they can be instantiated, can object oriended
>> programming also handle such.

Yes.

>> Because that seem almost AI like,

There is not much to it: the constructor can do the check.

>> so i guess some external mechanism must check so the objects attributes
>> do not collide?
> 
> I would say, drop the requirement of it being in JavaScript.

I would not, because today all widely distributed ECMAScript implementations 
that have “JavaScript” in their name support implicit setters and getters.  
That has been standardized for native objects in ECMAScript Edition 5 
(2009).

In this example, the setter would read from and write to a common registry, 
preventing the same property of two instances to have the same value.

> <https://www.amazon.com/Little-Java-Few-Patterns-Press-ebook
                                 ^^^^
> […]
> <script>

Now I am confused :)

> abstract class List<T>  {
                     ^^^
>     abstract append(value: T): List<T>
>     abstract concat(list: List<T>): List<T>
>     abstract length(): number
>     abstract isEmpty(): boolean
>     abstract toString(): string
>     //etc
> }
> […]
> 
> var xs: List<number> = new Cons(1, new Cons(2, new Cons(3, new Nil())))
  ^^^
> var ys: List<number> = new Nil().append(4).append(5).append(6)
> var zs: List<number> = xs.concat(ys)
> 
> console.log(zs.toString()) // 1::2::3::4::5::6::[]

Which programming language is this?


PointedEars
-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34466

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2018-01-05 15:15 -0800
Message-ID<f9aed92c-97fc-4600-a599-66696fb0dcfe@googlegroups.com>
In reply to#34464
Thomas 'PointedEars' Lahn wrote:
> Michael Haufe (TNO) wrote:

> > I would say, drop the requirement of it being in JavaScript.
> 
> I would not, because today all widely distributed ECMAScript implementations 
> that have “JavaScript” in their name support implicit setters and getters.  
> That has been standardized for native objects in ECMAScript Edition 5 
> (2009).

The reason I said drop the requirement was to prevent the OP from unnecessarily restricting what books he could read on the subject. 
 
> > <https://www.amazon.com/Little-Java-Few-Patterns-Press-ebook
>                                  ^^^^
> Now I am confused :)

If you know a better book on the topic for JavaScript specifically, I'm all ears. But the "Elephant Books" are very hard to beat due to their brevity [1]

[...] 

> Which programming language is this?

Apologies. It is TypeScript. I meant to specify, but forgot.


[1] <https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=Daniel+Friedman+and+Matthias+Felleisen&rh=i%3Aaps%2Ck%3ADaniel+Friedman+and+Matthias+Felleisen>

[toc] | [prev] | [next] | [standalone]


#34506

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2018-01-08 03:08 +0100
Message-ID<9538637.kl1s4tzyiK@PointedEars.de>
In reply to#34466
Michael Haufe (TNO) wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Which programming language is this?
> 
> Apologies. It is TypeScript. I meant to specify, but forgot.

I figured it might be an ECMAScript Ed. 4 Proposal implementation because
of “class”, “var”, and “:”, but the generics looked like Java to me.
I understand now that TypeScript also supports that.

ACK to the rest.

Happy New Year!
 
-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#34465

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-05 15:09 -0800
Message-ID<10845fc4-6701-47b9-a75b-b6ae1041553a@googlegroups.com>
In reply to#34460
Den fredag 5 januari 2018 kl. 20:51:55 UTC+1 skrev Michael Haufe (TNO):
> On Friday, January 5, 2018 at 12:25:50 PM UTC-6, Jonas Thörnvall wrote:
> > If one where to buy a single book, that covers most aspects of object oriented programming from scratch "using Javascript".
> > 
> > Which book to buy.
> > 
> > I can see the use of object oriented programming. 
> > For example i think i would like a midi track object, but how do you set boundaries for an object. For example that tracks can not use same channel and same out port? As i understand it an object have methods for its variables/"attributes?".
> > 
> > But rules for how they can be instantiated, can object oriended programming also handle such. Because that seem almost AI like, so i guess some external mechanism must check so the objects attributes do not collide?
> 
> 
> I would say, drop the requirement of it being in JavaScript.
> 
> Perhaps the best beginners book on the feeling of OOP is: "A little Java, A Few Patterns" by Felleisen and Friedman.
> 
> <https://www.amazon.com/Little-Java-Few-Patterns-Press-ebook/dp/B004GCK2MO/ref=sr_1_1?ie=UTF8&qid=1515180547&sr=8-1&keywords=A+little+Java%2C+a+few+patterns>
> 
> It's also less than 200 pages in length. 
> 
> Afterwards, follow the style of that book and try to write some basic data structures and algorithms in it. 
> 
> An example of the feel:
> 
> <script>
> abstract class List<T>  {
>     abstract append(value: T): List<T>
>     abstract concat(list: List<T>): List<T>
>     abstract length(): number
>     abstract isEmpty(): boolean
>     abstract toString(): string
>     //etc
> }
> class Nil<T> extends List<T> {
>     append(value: T): List<T> { return new Cons(value, this); }
>     concat(list: List<T>): List<T> { return list.isEmpty() ? this : list }
>     length(): number { return 0 }
>     isEmpty(): boolean { return true }
>     toString(): string { return "[]" }
>  }
> class Cons<T> {
>     constructor(readonly head: T, readonly tail: List<T>) { }
>     append(value: T): List<T> { return new Cons(this.head, this.tail.append(value)) }
>     concat(list: List<T>): List<T> {
>         return list.isEmpty() ? this : new Cons(this.head,this.tail.concat(list))
>     }
>     length(): number { return 1 + this.tail.length() }
>     isEmpty(): boolean { return false }
>     toString(): string { return `${this.head}::${this.tail}` }
> }
> 
> var xs: List<number> = new Cons(1, new Cons(2, new Cons(3, new Nil())))
> var ys: List<number> = new Nil().append(4).append(5).append(6)
> var zs: List<number> = xs.concat(ys)
> 
> console.log(zs.toString()) // 1::2::3::4::5::6::[]
> </script>

I start to think i may need a course in OOP, because really alot of the code i find in javascript, i have very hard time to interpretate. The language so rich and require so much preknowledge, i was never close to machine or assembly, but when your first programming language except from basic was cobol and pascal the scope of the language almost out of reach. It is guess work all the way, like this midi API, i can guess there is a listener somewhere "or is the ports listeners themself". What i get really worried about is that you can write same thing so many ways, i have kind of teflon memory so that is quite annoying it is hard to read code and see the plan of OOP when you come out of JSP and structural programming. Also i noticed in the JS files there is no init so to speak, just some weird syntax beyond my comprehension.

The JS file "midiprogramming" i have used as example for my little midi project started like this.

var context = new AudioContext(),
    oscillators = {};
if (navigator.requestMIDIAccess) {
    navigator.requestMIDIAccess()
        .then(success, failure);
}

There is so much implecit like contructs i understand it is an audio object.
But a code like oscillators = {}, what is that even supposed to mean?

What is navigator and requestMidiAccess are they part of the AudioContext object,is midi access a method?

Well it is all very confusing to me, and i guess you can not figure out the above by reading an OOP book, or?

 

[toc] | [prev] | [next] | [standalone]


#34467

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-05 15:21 -0800
Message-ID<5bd9a61b-ef96-4706-b2c0-f44d9f927c08@googlegroups.com>
In reply to#34465
Den lördag 6 januari 2018 kl. 00:09:28 UTC+1 skrev Jonas Thörnvall:
> Den fredag 5 januari 2018 kl. 20:51:55 UTC+1 skrev Michael Haufe (TNO):
> > On Friday, January 5, 2018 at 12:25:50 PM UTC-6, Jonas Thörnvall wrote:
> > > If one where to buy a single book, that covers most aspects of object oriented programming from scratch "using Javascript".
> > > 
> > > Which book to buy.
> > > 
> > > I can see the use of object oriented programming. 
> > > For example i think i would like a midi track object, but how do you set boundaries for an object. For example that tracks can not use same channel and same out port? As i understand it an object have methods for its variables/"attributes?".
> > > 
> > > But rules for how they can be instantiated, can object oriended programming also handle such. Because that seem almost AI like, so i guess some external mechanism must check so the objects attributes do not collide?
> > 
> > 
> > I would say, drop the requirement of it being in JavaScript.
> > 
> > Perhaps the best beginners book on the feeling of OOP is: "A little Java, A Few Patterns" by Felleisen and Friedman.
> > 
> > <https://www.amazon.com/Little-Java-Few-Patterns-Press-ebook/dp/B004GCK2MO/ref=sr_1_1?ie=UTF8&qid=1515180547&sr=8-1&keywords=A+little+Java%2C+a+few+patterns>
> > 
> > It's also less than 200 pages in length. 
> > 
> > Afterwards, follow the style of that book and try to write some basic data structures and algorithms in it. 
> > 
> > An example of the feel:
> > 
> > <script>
> > abstract class List<T>  {
> >     abstract append(value: T): List<T>
> >     abstract concat(list: List<T>): List<T>
> >     abstract length(): number
> >     abstract isEmpty(): boolean
> >     abstract toString(): string
> >     //etc
> > }
> > class Nil<T> extends List<T> {
> >     append(value: T): List<T> { return new Cons(value, this); }
> >     concat(list: List<T>): List<T> { return list.isEmpty() ? this : list }
> >     length(): number { return 0 }
> >     isEmpty(): boolean { return true }
> >     toString(): string { return "[]" }
> >  }
> > class Cons<T> {
> >     constructor(readonly head: T, readonly tail: List<T>) { }
> >     append(value: T): List<T> { return new Cons(this.head, this.tail.append(value)) }
> >     concat(list: List<T>): List<T> {
> >         return list.isEmpty() ? this : new Cons(this.head,this.tail.concat(list))
> >     }
> >     length(): number { return 1 + this.tail.length() }
> >     isEmpty(): boolean { return false }
> >     toString(): string { return `${this.head}::${this.tail}` }
> > }
> > 
> > var xs: List<number> = new Cons(1, new Cons(2, new Cons(3, new Nil())))
> > var ys: List<number> = new Nil().append(4).append(5).append(6)
> > var zs: List<number> = xs.concat(ys)
> > 
> > console.log(zs.toString()) // 1::2::3::4::5::6::[]
> > </script>
> 
> I start to think i may need a course in OOP, because really alot of the code i find in javascript, i have very hard time to interpretate. The language so rich and require so much preknowledge, i was never close to machine or assembly, but when your first programming language except from basic was cobol and pascal the scope of the language almost out of reach. It is guess work all the way, like this midi API, i can guess there is a listener somewhere "or is the ports listeners themself". What i get really worried about is that you can write same thing so many ways, i have kind of teflon memory so that is quite annoying it is hard to read code and see the plan of OOP when you come out of JSP and structural programming. Also i noticed in the JS files there is no init so to speak, just some weird syntax beyond my comprehension.
> 
> The JS file "midiprogramming" i have used as example for my little midi project started like this.
> 
> var context = new AudioContext(),
>     oscillators = {};
> if (navigator.requestMIDIAccess) {
>     navigator.requestMIDIAccess()
>         .then(success, failure);
> }
> 
> There is so much implecit like contructs i understand it is an audio object.
> But a code like oscillators = {}, what is that even supposed to mean?
> 
> What is navigator and requestMidiAccess are they part of the AudioContext object,is midi access a method?
> 
> Well it is all very confusing to me, and i guess you can not figure out the above by reading an OOP book, or?

It is kind of scary when you can't "understand" and interpretate code to try to adjust/fiddle it.

Like this
  for (input = inputs.next(); input && !input.done; input = inputs.next()) {
         var deviceIn = input.value.name;
         var optin = document.createElement("option");
         optin.text = deviceIn;
         document.getElementById("in_portsel").add(optin);
        // each time there is a midi message call the onMIDIMessage function
        input.value.onmidimessage = onMIDIMessage;
        
    }
It somehow reads in all input ports in a loop, and then suddenly ***bang*** it some sort of listener picking up midi messages? This code listens to all ports "omni", but i do not see what open all the ports? If i just wanted to listen to one?

And here is am totally lost input.value.onmidimessage = onMIDIMessage;

onMIDIMessage is a function? But why is there no parentheses and what is input.value.omnimidimessage? And why is there a equal sign between, to me it must be parameters? I just don't get the syntax so all become a hack.

[toc] | [prev] | [next] | [standalone]


#34468

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-05 15:27 -0800
Message-ID<ab225b7e-aafe-4697-9fbc-5f4477b5181a@googlegroups.com>
In reply to#34467
Den lördag 6 januari 2018 kl. 00:21:25 UTC+1 skrev Jonas Thörnvall:
> Den lördag 6 januari 2018 kl. 00:09:28 UTC+1 skrev Jonas Thörnvall:
> > Den fredag 5 januari 2018 kl. 20:51:55 UTC+1 skrev Michael Haufe (TNO):
> > > On Friday, January 5, 2018 at 12:25:50 PM UTC-6, Jonas Thörnvall wrote:
> > > > If one where to buy a single book, that covers most aspects of object oriented programming from scratch "using Javascript".
> > > > 
> > > > Which book to buy.
> > > > 
> > > > I can see the use of object oriented programming. 
> > > > For example i think i would like a midi track object, but how do you set boundaries for an object. For example that tracks can not use same channel and same out port? As i understand it an object have methods for its variables/"attributes?".
> > > > 
> > > > But rules for how they can be instantiated, can object oriended programming also handle such. Because that seem almost AI like, so i guess some external mechanism must check so the objects attributes do not collide?
> > > 
> > > 
> > > I would say, drop the requirement of it being in JavaScript.
> > > 
> > > Perhaps the best beginners book on the feeling of OOP is: "A little Java, A Few Patterns" by Felleisen and Friedman.
> > > 
> > > <https://www.amazon.com/Little-Java-Few-Patterns-Press-ebook/dp/B004GCK2MO/ref=sr_1_1?ie=UTF8&qid=1515180547&sr=8-1&keywords=A+little+Java%2C+a+few+patterns>
> > > 
> > > It's also less than 200 pages in length. 
> > > 
> > > Afterwards, follow the style of that book and try to write some basic data structures and algorithms in it. 
> > > 
> > > An example of the feel:
> > > 
> > > <script>
> > > abstract class List<T>  {
> > >     abstract append(value: T): List<T>
> > >     abstract concat(list: List<T>): List<T>
> > >     abstract length(): number
> > >     abstract isEmpty(): boolean
> > >     abstract toString(): string
> > >     //etc
> > > }
> > > class Nil<T> extends List<T> {
> > >     append(value: T): List<T> { return new Cons(value, this); }
> > >     concat(list: List<T>): List<T> { return list.isEmpty() ? this : list }
> > >     length(): number { return 0 }
> > >     isEmpty(): boolean { return true }
> > >     toString(): string { return "[]" }
> > >  }
> > > class Cons<T> {
> > >     constructor(readonly head: T, readonly tail: List<T>) { }
> > >     append(value: T): List<T> { return new Cons(this.head, this.tail.append(value)) }
> > >     concat(list: List<T>): List<T> {
> > >         return list.isEmpty() ? this : new Cons(this.head,this.tail.concat(list))
> > >     }
> > >     length(): number { return 1 + this.tail.length() }
> > >     isEmpty(): boolean { return false }
> > >     toString(): string { return `${this.head}::${this.tail}` }
> > > }
> > > 
> > > var xs: List<number> = new Cons(1, new Cons(2, new Cons(3, new Nil())))
> > > var ys: List<number> = new Nil().append(4).append(5).append(6)
> > > var zs: List<number> = xs.concat(ys)
> > > 
> > > console.log(zs.toString()) // 1::2::3::4::5::6::[]
> > > </script>
> > 
> > I start to think i may need a course in OOP, because really alot of the code i find in javascript, i have very hard time to interpretate. The language so rich and require so much preknowledge, i was never close to machine or assembly, but when your first programming language except from basic was cobol and pascal the scope of the language almost out of reach. It is guess work all the way, like this midi API, i can guess there is a listener somewhere "or is the ports listeners themself". What i get really worried about is that you can write same thing so many ways, i have kind of teflon memory so that is quite annoying it is hard to read code and see the plan of OOP when you come out of JSP and structural programming. Also i noticed in the JS files there is no init so to speak, just some weird syntax beyond my comprehension.
> > 
> > The JS file "midiprogramming" i have used as example for my little midi project started like this.
> > 
> > var context = new AudioContext(),
> >     oscillators = {};
> > if (navigator.requestMIDIAccess) {
> >     navigator.requestMIDIAccess()
> >         .then(success, failure);
> > }
> > 
> > There is so much implecit like contructs i understand it is an audio object.
> > But a code like oscillators = {}, what is that even supposed to mean?
> > 
> > What is navigator and requestMidiAccess are they part of the AudioContext object,is midi access a method?
> > 
> > Well it is all very confusing to me, and i guess you can not figure out the above by reading an OOP book, or?
> 
> It is kind of scary when you can't "understand" and interpretate code to try to adjust/fiddle it.
> 
> Like this
>   for (input = inputs.next(); input && !input.done; input = inputs.next()) {
>          var deviceIn = input.value.name;
>          var optin = document.createElement("option");
>          optin.text = deviceIn;
>          document.getElementById("in_portsel").add(optin);
>         // each time there is a midi message call the onMIDIMessage function
>         input.value.onmidimessage = onMIDIMessage;
>         
>     }
> It somehow reads in all input ports in a loop, and then suddenly ***bang*** it some sort of listener picking up midi messages? This code listens to all ports "omni", but i do not see what open all the ports? If i just wanted to listen to one?
> 
> And here is am totally lost input.value.onmidimessage = onMIDIMessage;
> 
> onMIDIMessage is a function? But why is there no parentheses and what is input.value.omnimidimessage? And why is there a equal sign between, to me it must be parameters? I just don't get the syntax so all become a hack.

I understand arrays and string handling using functions it is straightforward, sometimes i understand the implementation of the listeners within code, but most times the code looks really confusing i must say.

[toc] | [prev] | [next] | [standalone]


#34461

FromJulio Di Egidio <julio@diegidio.name>
Date2018-01-05 12:09 -0800
Message-ID<f535eff4-a2cd-40f9-aa54-5cf02864e2fa@googlegroups.com>
In reply to#34459
On Friday, January 5, 2018 at 7:25:50 PM UTC+1, Jonas Thörnvall wrote:

> If one where to buy a single book, that covers most aspects of object
> oriented programming from scratch "using Javascript".

OO can be a language or it can be an architectural approach, just do not
confuse the two things: JS is a *functional* language (with prototypical
inheritance, which is all but OO), and while JS is so powerful a language
that it's not even difficult to implement the whole OO abstraction on top
of it, any such thing remains an aberration unless it's just for study.

That said, be aware that OO is very much overrated and actually inadequate
for most but some very specific situations.  The great emphasis and hype
around OO is simply a product of some 25 years of vile speculations across
the whole software industry: outright bullshit on sale, from the fact that
OO is modular, which it least is (functional is modular), to the fact that
OO is nearest to the informal domain, which again is the exact opposite of
the truth: we mainly think functional.  --  Just scratching the surface...

HTH,

Julio

[toc] | [prev] | [next] | [standalone]


#34462

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2018-01-05 13:01 -0800
Message-ID<f2ed9b14-66d5-46be-ac65-a7f8cea1a46d@googlegroups.com>
In reply to#34461
Julio Di Egidio wrote:

> OO can be a language or it can be an architectural approach.

I don't think there is a difference semantically.  

>, just do not
> confuse the two things: JS is a *functional* language (with prototypical
> inheritance, which is all but OO),

David Ungar would disagree, along with most of the Self community [1]

> and while JS is so powerful a language
> that it's not even difficult to implement the whole OO abstraction on top
> of it, any such thing remains an aberration unless it's just for study.

We've been through this before. JavaScript is clearly Object Oriented [2]. If you disagree, you need to define what you call "Object Oriented" then.

> That said, be aware that OO is very much overrated and actually inadequate
> for most but some very specific situations.

Overrated? Maybe. That seems to be more of a judgement of the industry than the paradigm though.

Inadequate? No more than functional programming would be. They are dual paradigms and suffer from dual limitations:

OOP: I have data but don't know the operation to apply. I have to use Subtype Polymorphism to figure it out.

FP: I have an operation, but I don't know what data to apply, so I have to use a switch or typecase construct to figure it out.

Example:

//OOP:
abstract class Shape {
    abstract print(): string
}
class Circle extends Shape {
    print(): string { return "Circle" }
}
class Triangle extends Shape {
    print(): string { return "Triangle" }
}

myShape.print()

//FP
data Shape = Circle | Triangle

function print(s: Shape) {
    switch(s) {
        case s instanceof Circle: return "Circle"
        case s instanceof Triangle: return "Triangle"
    }
}

> The great emphasis and hype
> around OO is simply a product of some 25 years of vile speculations across
> the whole software industry: outright bullshit on sale, from the fact that
> OO is modular, which it least is (functional is modular), to the fact that
> OO is nearest to the informal domain, which again is the exact opposite of
> the truth: 

Historically the industry was mostly procedural and imperative in it's programming. OOPs main sale was Encapsulation and Structured Programming. It was definitely over-hyped though and abused as a term. Alan Kay is credited for inventing the term. To quote him on the matter: "I made up the term object-oriented, and I can tell you I did not have C++ in mind."

> we mainly think functional.  --  Just scratching the surface...

This is debatable. I don't know what we think closest to. I am aware of the arguments of prototypical vs classical OOP though [3] and both sides. DO you have any reference or justification for this?

[1] "SELF: THE POWER OF SIMPLICITY" <http://www.selflanguage.org/_static/published/self-power.pdf>
[2] <https://groups.google.com/d/msg/comp.lang.javascript/7yR6urAZypU/CF7Ucfj-BAAJ>
[3] "Psychological Criticism of the Prototype-Based Object-Oriented Languages" <https://web.archive.org/web/20100316225046/http://www.helsinki.fi:80/~jppesone/papers/kandi.html>

[toc] | [prev] | [next] | [standalone]


#34463

FromJulio Di Egidio <julio@diegidio.name>
Date2018-01-05 14:38 -0800
Message-ID<41aa51ac-693c-44ab-9bae-db0b661ba9df@googlegroups.com>
In reply to#34462
On Friday, January 5, 2018 at 10:02:09 PM UTC+1, Michael Haufe (TNO) wrote:
> Julio Di Egidio wrote:
> 
> > OO can be a language or it can be an architectural approach.
> 
> I don't think there is a difference semantically.

You are simply wrong, that difference is in fact basic and quite important.
Of course, you could have asked "why is that difference important", but of
course you didn't, you rather "think".

> David Ungar would disagree, along with most of the Self community [1]

I have been debunking the whole bandwagon publicly and for years, and at
my own costs.  You as most people just go with the authorities, which is
part of a now globalised problem, not any sensible objection to whatever
anybody is saying.

> Historically the industry was mostly procedural and imperative in it's
> programming. OOPs main sale was Encapsulation and Structured Programming.

Yes, a sale, as the whole thing remains unmitigated bullshit: indeed note
that OO programming is imperative itself, while structured programming
exists since the times GOSUB was invented: just to mention two immediate
things and what utter nonsense passes over that board just because some
nice guy is selling it and the rest cannot do better than parrot each other.
Overall, you literally do not know what you are talking about.

> Alan Kay is credited for inventing the term. To quote him on the matter:
> "I made up the term object-oriented, and I can tell you I did not have C++
> in mind."

Exactly, back to languages vs paradigms, but you'll deny it if it comes from
me, while you will warship it and whatever if it comes from any of the star
system gurus.

> We've been through this before.

That's right, but this is a public group and my replies are for those who
can benefit.

*Plonk*

Julio

[toc] | [prev] | [next] | [standalone]


#34469

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2018-01-05 15:29 -0800
Message-ID<ee45a970-0349-404d-a6e4-45fdbd16bf53@googlegroups.com>
In reply to#34463
Julio Di Egidio wrote:
> Michael Haufe (TNO) wrote:
> > Julio Di Egidio wrote:
> > 
> > > OO can be a language or it can be an architectural approach.
> > 
> > I don't think there is a difference semantically.
> 
> You are simply wrong, that difference is in fact basic and quite important.
> Of course, you could have asked "why is that difference important", but of
> course you didn't, you rather "think".

Somebody has to think. If you won't, than I will... 

I've asked you to justify your claims more than once in the past, and I'm still waiting. I may be a masochist for this, but I do have limits.

> > David Ungar would disagree, along with most of the Self community [1]
> 
> I have been debunking the whole bandwagon publicly and for years, and at
> my own costs.

Reference please.

> You as most people just go with the authorities, which is
> part of a now globalised problem, not any sensible objection to whatever
> anybody is saying.

Not simply "just", but generally yes. Some "authorities" are more equal than others. Ungar is not a lesser mortal in this field, so what *exactly* are you objecting to?

> > Historically the industry was mostly procedural and imperative in it's
> > programming. OOPs main sale was Encapsulation and Structured Programming.
> 
> Yes, a sale, as the whole thing remains unmitigated bullshit: indeed note
> that OO programming is imperative itself,

Most, not all. My List implementation is not. Can you see the difference?

> > Alan Kay is credited for inventing the term. To quote him on the matter:
> > "I made up the term object-oriented, and I can tell you I did not have C++
> > in mind."
> 
> Exactly, back to languages vs paradigms, but you'll deny it if it comes from
> me, while you will warship it and whatever if it comes from any of the star
> system gurus.

Why the assumption that languages and paradigms have to be separable and in conflict?

> > We've been through this before.
> 
> That's right, but this is a public group and my replies are for those who
> can benefit.

Still not sure who benefits. It still looks vacuous to me.

[toc] | [prev] | [next] | [standalone]


#34470

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-05 15:49 -0800
Message-ID<431c000b-abb7-4dc1-a692-35d29b6f9456@googlegroups.com>
In reply to#34469
Den lördag 6 januari 2018 kl. 00:29:51 UTC+1 skrev Michael Haufe (TNO):
> Julio Di Egidio wrote:
> > Michael Haufe (TNO) wrote:
> > > Julio Di Egidio wrote:
> > > 
> > > > OO can be a language or it can be an architectural approach.
> > > 
> > > I don't think there is a difference semantically.
> > 
> > You are simply wrong, that difference is in fact basic and quite important.
> > Of course, you could have asked "why is that difference important", but of
> > course you didn't, you rather "think".
> 
> Somebody has to think. If you won't, than I will... 
> 
> I've asked you to justify your claims more than once in the past, and I'm still waiting. I may be a masochist for this, but I do have limits.
> 
> > > David Ungar would disagree, along with most of the Self community [1]
> > 
> > I have been debunking the whole bandwagon publicly and for years, and at
> > my own costs.
> 
> Reference please.
> 
> > You as most people just go with the authorities, which is
> > part of a now globalised problem, not any sensible objection to whatever
> > anybody is saying.
> 
> Not simply "just", but generally yes. Some "authorities" are more equal than others. Ungar is not a lesser mortal in this field, so what *exactly* are you objecting to?
> 
> > > Historically the industry was mostly procedural and imperative in it's
> > > programming. OOPs main sale was Encapsulation and Structured Programming.
> > 
> > Yes, a sale, as the whole thing remains unmitigated bullshit: indeed note
> > that OO programming is imperative itself,
> 
> Most, not all. My List implementation is not. Can you see the difference?
> 
> > > Alan Kay is credited for inventing the term. To quote him on the matter:
> > > "I made up the term object-oriented, and I can tell you I did not have C++
> > > in mind."
> > 
> > Exactly, back to languages vs paradigms, but you'll deny it if it comes from
> > me, while you will warship it and whatever if it comes from any of the star
> > system gurus.
> 
> Why the assumption that languages and paradigms have to be separable and in conflict?
> 
> > > We've been through this before.
> > 
> > That's right, but this is a public group and my replies are for those who
> > can benefit.
> 
> Still not sure who benefits. It still looks vacuous to me.


Here is the midicode i hacked together so far but probably i do unecessary things, and maybe create objects that i am not even aware about.

Basicly i read midi in and out ports into select list adn create options. And have field to set/write program for each midichannel in an optionlist.

Probably i would want an object "track" that hold both channel and program and that also take care of the midi in port messages my keyboard send and forward to the midi out module. 

In a sequenser one probably also want the object to also have a timecode with each message.

But it gets confusing is the track the object holding messages in a object? "if there is such"
 
I can probably make a sequenser oldschool by starting a timer and set timecodes on the messages, and store them as strings in an array and it will work. But it will be a hack? 

var context = new AudioContext(),
    oscillators = {};

outportindex=10;
programC=16;
channelC=1;
NOTE_ON=0x90;
NOTE_OFF=0x80;

function midiInit(){

if (navigator.requestMIDIAccess) {
    navigator.requestMIDIAccess()
        .then(success, failure);
}

} 

function failure () {
    console.error('No access to your midi devices.'+ + msg )
}

function onMIDISuccess( midiAccess ) {
  console.log( "MIDI ready!" );
  var input = midiAccess.inputs.entries.next();
  if (input)
    input.onmidimessage = echoMIDIMessage;
  output = midiAccess.outputs.values().next().value;
  if (!input || !output)
    console.log("Uh oh! Couldn't get i/o ports.");
} 

function success (midi) {
    mid=midi;
    inputs = midi.inputs.values();
    outputs = midi.outputs.values();
    // inputs outputs are Iterators
    for (output = outputs.next(); output && !output.done; output = outputs.next()) {
       var deviceOut = output.value.name;
       console.log(deviceOut);
       var optout = document.createElement("option");
       optout.text = deviceOut;
       document.getElementById("out_portsel").add(optout);

    }
    for (input = inputs.next(); input && !input.done; input = inputs.next()) {
         var deviceIn = input.value.name;
         var optin = document.createElement("option");
         optin.text = deviceIn;
         document.getElementById("in_portsel").add(optin);
        // each time there is a midi message call the onMIDIMessage function
        input.value.onmidimessage = onMIDIMessage;
        
    }
   document.getElementById("out_portsel").selectedIndex=outportindex;
   changeProgram();
}



function echoMIDIMessage( event ) {
  if (output) {
    output.send( event.data, event.timestamp );
  }
}

function changeMidiChannel(){
console.log("Change MIDI channel");
channelC=document.getElementById("out_channel").selectedIndex+1;
console.log("channel ",channelC);
if (channelC==1) {NOTE_ON=0xC0}
else if (channelC==1) {NOTE_ON=0x90; NOTE_OFF=0x80;}
else if (channelC==2) {NOTE_ON=0x91; NOTE_OFF=0x81;}
else if (channelC==3) {NOTE_ON=0x92;NOTE_OFF=0x82;}
else if (channelC==4) {NOTE_ON=0x93;NOTE_OFF=0x83;}
else if (channelC==5) {NOTE_ON=0x94;NOTE_OFF=0x84;}
else if (channelC==6) {NOTE_ON=0x95;NOTE_OFF=0x85;}
else if (channelC==7) {NOTE_ON=0x96;NOTE_OFF=0x86;}
else if (channelC==8) {NOTE_ON=0x97;NOTE_OFF=0x87;}
else if (channelC==9) {NOTE_ON=0x98;NOTE_OFF=0x88;}
else if (channelC==10) {NOTE_ON=0x99;NOTE_OFF=0x89;}
else if (channelC==11) {NOTE_ON=0xA0;NOTE_OFF=0x8A;}
else if (channelC==12) {NOTE_ON=0xA1;NOTE_OFF=0x8B;}
else if (channelC==13) {NOTE_ON=0xA2;NOTE_OFF=0x8C;}
else if (channelC==14) {NOTE_ON=0xA3;NOTE_OFF=0x8D;}
else if (channelC==15) {NOTE_ON=0xA4;NOTE_OFF=0x8E;}
else if (channelC==16) {NOTE_ON=0xA5;NOTE_OFF=0x8F;}
output = mid.outputs.get(outportindex);
console.log("Channel ",NOTE_ON," program ",programC);
}

function midiToOutPort(message){
 console.log(message.data[1]);
 output = mid.outputs.get(outportindex);
 console.log("Messag type",message.data[0]);
 if(message.data[0]==144 && channelC!=1){message.data[0]=NOTE_ON;}
 if(message.data[0]==128 && channelC!=1){message.data[0]=NOTE_OFF;}
 console.log("Messag type",message.data[0]);
 var noteOnMessage = [message.data[0], message.data[1], message.data[2]];
 output.send( noteOnMessage );  
 
}


function changeProgram(){
console.log("Change program");
sysexC=192+channelC-1;
programC=document.getElementById("prog_sel").value
output = mid.outputs.get(outportindex);
var programChange = [sysexC,programC];
output.send(programChange );  
}


function changeOutPort(){
//outportindex = document.getElementById("out_portsel").value;
outportindex=document.getElementById("out_portsel").selectedIndex;
console.log("selected index "+outportindex);
}

function onMIDIMessage (message) {
  midiToOutPort(message);
  //synth(message);
}

[toc] | [prev] | [next] | [standalone]


#34471

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-06 02:23 -0800
Message-ID<e5acf83e-7a90-428c-9867-8815a2cf657d@googlegroups.com>
In reply to#34470
Den lördag 6 januari 2018 kl. 00:49:28 UTC+1 skrev Jonas Thörnvall:
> Den lördag 6 januari 2018 kl. 00:29:51 UTC+1 skrev Michael Haufe (TNO):
> > Julio Di Egidio wrote:
> > > Michael Haufe (TNO) wrote:
> > > > Julio Di Egidio wrote:
> > > > 
> > > > > OO can be a language or it can be an architectural approach.
> > > > 
> > > > I don't think there is a difference semantically.
> > > 
> > > You are simply wrong, that difference is in fact basic and quite important.
> > > Of course, you could have asked "why is that difference important", but of
> > > course you didn't, you rather "think".
> > 
> > Somebody has to think. If you won't, than I will... 
> > 
> > I've asked you to justify your claims more than once in the past, and I'm still waiting. I may be a masochist for this, but I do have limits.
> > 
> > > > David Ungar would disagree, along with most of the Self community [1]
> > > 
> > > I have been debunking the whole bandwagon publicly and for years, and at
> > > my own costs.
> > 
> > Reference please.
> > 
> > > You as most people just go with the authorities, which is
> > > part of a now globalised problem, not any sensible objection to whatever
> > > anybody is saying.
> > 
> > Not simply "just", but generally yes. Some "authorities" are more equal than others. Ungar is not a lesser mortal in this field, so what *exactly* are you objecting to?
> > 
> > > > Historically the industry was mostly procedural and imperative in it's
> > > > programming. OOPs main sale was Encapsulation and Structured Programming.
> > > 
> > > Yes, a sale, as the whole thing remains unmitigated bullshit: indeed note
> > > that OO programming is imperative itself,
> > 
> > Most, not all. My List implementation is not. Can you see the difference?
> > 
> > > > Alan Kay is credited for inventing the term. To quote him on the matter:
> > > > "I made up the term object-oriented, and I can tell you I did not have C++
> > > > in mind."
> > > 
> > > Exactly, back to languages vs paradigms, but you'll deny it if it comes from
> > > me, while you will warship it and whatever if it comes from any of the star
> > > system gurus.
> > 
> > Why the assumption that languages and paradigms have to be separable and in conflict?
> > 
> > > > We've been through this before.
> > > 
> > > That's right, but this is a public group and my replies are for those who
> > > can benefit.
> > 
> > Still not sure who benefits. It still looks vacuous to me.
> 
> 
> Here is the midicode i hacked together so far but probably i do unecessary things, and maybe create objects that i am not even aware about.
> 
> Basicly i read midi in and out ports into select list adn create options. And have field to set/write program for each midichannel in an optionlist.
> 
> Probably i would want an object "track" that hold both channel and program and that also take care of the midi in port messages my keyboard send and forward to the midi out module. 
> 
> In a sequenser one probably also want the object to also have a timecode with each message.
> 
> But it gets confusing is the track the object holding messages in a object? "if there is such"
>  
> I can probably make a sequenser oldschool by starting a timer and set timecodes on the messages, and store them as strings in an array and it will work. But it will be a hack? 
> 
> var context = new AudioContext(),
>     oscillators = {};
> 
> outportindex=10;
> programC=16;
> channelC=1;
> NOTE_ON=0x90;
> NOTE_OFF=0x80;
> 
> function midiInit(){
> 
> if (navigator.requestMIDIAccess) {
>     navigator.requestMIDIAccess()
>         .then(success, failure);
> }
> 
> } 
> 
> function failure () {
>     console.error('No access to your midi devices.'+ + msg )
> }
> 
> function onMIDISuccess( midiAccess ) {
>   console.log( "MIDI ready!" );
>   var input = midiAccess.inputs.entries.next();
>   if (input)
>     input.onmidimessage = echoMIDIMessage;
>   output = midiAccess.outputs.values().next().value;
>   if (!input || !output)
>     console.log("Uh oh! Couldn't get i/o ports.");
> } 
> 
> function success (midi) {
>     mid=midi;
>     inputs = midi.inputs.values();
>     outputs = midi.outputs.values();
>     // inputs outputs are Iterators
>     for (output = outputs.next(); output && !output.done; output = outputs.next()) {
>        var deviceOut = output.value.name;
>        console.log(deviceOut);
>        var optout = document.createElement("option");
>        optout.text = deviceOut;
>        document.getElementById("out_portsel").add(optout);
> 
>     }
>     for (input = inputs.next(); input && !input.done; input = inputs.next()) {
>          var deviceIn = input.value.name;
>          var optin = document.createElement("option");
>          optin.text = deviceIn;
>          document.getElementById("in_portsel").add(optin);
>         // each time there is a midi message call the onMIDIMessage function
>         input.value.onmidimessage = onMIDIMessage;
>         
>     }
>    document.getElementById("out_portsel").selectedIndex=outportindex;
>    changeProgram();
> }
> 
> 
> 
> function echoMIDIMessage( event ) {
>   if (output) {
>     output.send( event.data, event.timestamp );
>   }
> }
> 
> function changeMidiChannel(){
> console.log("Change MIDI channel");
> channelC=document.getElementById("out_channel").selectedIndex+1;
> console.log("channel ",channelC);
> if (channelC==1) {NOTE_ON=0xC0}
> else if (channelC==1) {NOTE_ON=0x90; NOTE_OFF=0x80;}
> else if (channelC==2) {NOTE_ON=0x91; NOTE_OFF=0x81;}
> else if (channelC==3) {NOTE_ON=0x92;NOTE_OFF=0x82;}
> else if (channelC==4) {NOTE_ON=0x93;NOTE_OFF=0x83;}
> else if (channelC==5) {NOTE_ON=0x94;NOTE_OFF=0x84;}
> else if (channelC==6) {NOTE_ON=0x95;NOTE_OFF=0x85;}
> else if (channelC==7) {NOTE_ON=0x96;NOTE_OFF=0x86;}
> else if (channelC==8) {NOTE_ON=0x97;NOTE_OFF=0x87;}
> else if (channelC==9) {NOTE_ON=0x98;NOTE_OFF=0x88;}
> else if (channelC==10) {NOTE_ON=0x99;NOTE_OFF=0x89;}
> else if (channelC==11) {NOTE_ON=0xA0;NOTE_OFF=0x8A;}
> else if (channelC==12) {NOTE_ON=0xA1;NOTE_OFF=0x8B;}
> else if (channelC==13) {NOTE_ON=0xA2;NOTE_OFF=0x8C;}
> else if (channelC==14) {NOTE_ON=0xA3;NOTE_OFF=0x8D;}
> else if (channelC==15) {NOTE_ON=0xA4;NOTE_OFF=0x8E;}
> else if (channelC==16) {NOTE_ON=0xA5;NOTE_OFF=0x8F;}
> output = mid.outputs.get(outportindex);
> console.log("Channel ",NOTE_ON," program ",programC);
> }
> 
> function midiToOutPort(message){
>  console.log(message.data[1]);
>  output = mid.outputs.get(outportindex);
>  console.log("Messag type",message.data[0]);
>  if(message.data[0]==144 && channelC!=1){message.data[0]=NOTE_ON;}
>  if(message.data[0]==128 && channelC!=1){message.data[0]=NOTE_OFF;}
>  console.log("Messag type",message.data[0]);
>  var noteOnMessage = [message.data[0], message.data[1], message.data[2]];
>  output.send( noteOnMessage );  
>  
> }
> 
> 
> function changeProgram(){
> console.log("Change program");
> sysexC=192+channelC-1;
> programC=document.getElementById("prog_sel").value
> output = mid.outputs.get(outportindex);
> var programChange = [sysexC,programC];
> output.send(programChange );  
> }
> 
> 
> function changeOutPort(){
> //outportindex = document.getElementById("out_portsel").value;
> outportindex=document.getElementById("out_portsel").selectedIndex;
> console.log("selected index "+outportindex);
> }
> 
> function onMIDIMessage (message) {
>   midiToOutPort(message);
>   //synth(message);
> }

I finally find a tutorial that explain somewhat what is going on.

https://code.tutsplus.com/tutorials/introduction-to-web-midi--cms-25220

But it is very vague, for example.

In order to get the input data from our device, we first create a variable and assign it midi.inputs.values() like so.


var inputs = midi.inputs.values();

Is midi.input.values(); a function or a method? How do i know the difference?
midi is an object?
input an attribute of that object?
values a property of input?

I even lost on the terminology here.

But if it is a function/method why the **fuc** are the brackets at the values?
I get that the **thing** is assigned to a variable inputs.

These so called built in methods/function is there no specification on what they  return. I also wondered why some functions called properties, is it because they  do not do anything with the ***thing***. Take length i mean it do something it count the objects of the array? If you knew to javascript how the fuck are you supposed to see it is a function that return number of elements of an array?

I do understand that alot is design decisions coming out of some model?
But it make it cumbersome to read due to semantics, or do the semantics carry meaning?

var arr3 = arr1.concat(arr2);

I mean what the fuck is this i don't see the point? why not
var arr3=concat(arr1,arr2);

I mean the above i get that arr2 is a parameter and concat is a method/function please explain the difference.

But what the fuck is arr1.concat supposed to mean?
To me it seem to say that arr1 "arrays" have a method i that correct?

Also they call it Array.prototype.concat()
What the fuck is prototype supposed to mean in this linguistic mishmash? I see it used but i never fully understood what a prototype is?

If this convoluted semantics really needed? why isn't it then explicit in the language so people by eyeballing the code can see what is an array a method when you stuck things together like 

full.confusion.inmypants=getIt 

input.value.onmidimessage = onMIDIMessage; 

how the fuck am i supposed to interpretate that one by eyeball it, there is no clue to tell what is a variable or method or prototype or function? But it does not matter because getIt will call a function but you can't fucking see it? If you do not know the full language every built in method how can you know?

Just tell me how could you learn an AI to understand that language, without you let it know every

my.balls=jump

input.onmidimessage = echoMIDIMessage;

It can't be the meaning that you must know every command, method and built in objects "implicit" within the language to be able to understand code when you read it?

I am all far that a variable name that the programmer define can hold what the fuck ever, "because then somewhere in the code you can find it". But when there is built in objects and methods hidden in a noneexplicit semantics. It does not fucking tell what it is, how can i figure it out by just eyeball? 

my.balls=jump

I can't track down the meaning within the code?
 

[toc] | [prev] | [next] | [standalone]


#34472

FromJulio Di Egidio <julio@diegidio.name>
Date2018-01-06 03:25 -0800
Message-ID<409a0b82-3074-4c3e-96a3-5c03c25037f9@googlegroups.com>
In reply to#34471
On Saturday, January 6, 2018 at 11:23:16 AM UTC+1, Jonas Thörnvall wrote:
<snip>
> var inputs = midi.inputs.values();
> 
> Is midi.input.values(); a function or a method?

There are no methods in JS, only functions, in fact closures.
Then there are objects with properties, not attributes.

Those properties, just like variables, can hold any value, including
references to functions (again, to closures), e.g.:

myobj.func = function () { return dosomething(); };

> How do i know the difference?

RTFM?  JS is notoriously the world's most misunderstood programming language
ever, OTOH a language spec as well as some good enough tutorials are not
that difficult to find really:

<https://developer.mozilla.org/bm/docs/Web/JavaScript>

> my.balls=jump
> 
> I can't track down the meaning within the code?

You cannot track the meaning of anything in that sense, i.e. by just
considering the rules of the language: readability (which includes
readable meaningfulness), just as correctness, is something we *strive*
for...

Julio

[toc] | [prev] | [next] | [standalone]


#34473

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-06 03:39 -0800
Message-ID<f2ea2800-20fa-48d9-bcec-3386709fab0e@googlegroups.com>
In reply to#34472
Den lördag 6 januari 2018 kl. 12:25:13 UTC+1 skrev Julio Di Egidio:
> On Saturday, January 6, 2018 at 11:23:16 AM UTC+1, Jonas Thörnvall wrote:
> <snip>
> > var inputs = midi.inputs.values();
> > 
> > Is midi.input.values(); a function or a method?
> 
> There are no methods in JS, only functions, in fact closures.
> Then there are objects with properties, not attributes.
> 
> Those properties, just like variables, can hold any value, including
> references to functions (again, to closures), e.g.:
> 
> myobj.func = function () { return dosomething(); };
> 
> > How do i know the difference?
> 
> RTFM?  JS is notoriously the world's most misunderstood programming language
> ever, OTOH a language spec as well as some good enough tutorials are not
> that difficult to find really:
> 
> <https://developer.mozilla.org/bm/docs/Web/JavaScript>
> 
> > my.balls=jump
> > 
> > I can't track down the meaning within the code?
> 
> You cannot track the meaning of anything in that sense, i.e. by just
> considering the rules of the language: readability (which includes
> readable meaningfulness), just as correctness, is something we *strive*
> for...
> 
> Julio

But should one not be able to differentiate a function from a variable or from a listener. A value allocation from a function call?

Is this a value allocation or a function call.

my.balls=jump;

[toc] | [prev] | [next] | [standalone]


#34476

FromJulio Di Egidio <julio@diegidio.name>
Date2018-01-06 04:24 -0800
Message-ID<466082d9-7d98-4b92-bd1a-fe639f4c50d8@googlegroups.com>
In reply to#34473
On Saturday, January 6, 2018 at 12:39:55 PM UTC+1, Jonas Thörnvall wrote:
> Den lördag 6 januari 2018 kl. 12:25:13 UTC+1 skrev Julio Di Egidio:
> > On Saturday, January 6, 2018 at 11:23:16 AM UTC+1, Jonas Thörnvall wrote:
> > <snip>
> > > var inputs = midi.inputs.values();
> > > 
> > > Is midi.input.values(); a function or a method?
> > 
> > There are no methods in JS, only functions, in fact closures.
> > Then there are objects with properties, not attributes.
> > 
> > Those properties, just like variables, can hold any value, including
> > references to functions (again, to closures), e.g.:
> > 
> > myobj.func = function () { return dosomething(); };
> > 
> > > How do i know the difference?
> > 
> > RTFM?  JS is notoriously the world's most misunderstood programming language
> > ever, OTOH a language spec as well as some good enough tutorials are not
> > that difficult to find really:
> > 
> > <https://developer.mozilla.org/bm/docs/Web/JavaScript>
> > 
> > > my.balls=jump
> > > 
> > > I can't track down the meaning within the code?
> > 
> > You cannot track the meaning of anything in that sense, i.e. by just
> > considering the rules of the language: readability (which includes
> > readable meaningfulness), just as correctness, is something we *strive*
> > for...
> 
> But should one not be able to differentiate a function from a variable or
> from a listener. A value allocation from a function call?

Not just by the name unless the programmer is using proper conventions, and
even then one should be careful when reviewing code, as generally very few
programmers can write decent code, but even the good programmers make
mistakes and are subject to fatigue.

> Is this a value allocation or a function call.
> 
> my.balls=jump;

That is an *assignment*, dumbass.  RTFM.

*Plonk*

Julio

[toc] | [prev] | [next] | [standalone]


#34477

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-06 05:26 -0800
Message-ID<6832c789-d67b-4d65-a2b3-4c119eb0b883@googlegroups.com>
In reply to#34476
Den lördag 6 januari 2018 kl. 13:24:58 UTC+1 skrev Julio Di Egidio:
> On Saturday, January 6, 2018 at 12:39:55 PM UTC+1, Jonas Thörnvall wrote:
> > Den lördag 6 januari 2018 kl. 12:25:13 UTC+1 skrev Julio Di Egidio:
> > > On Saturday, January 6, 2018 at 11:23:16 AM UTC+1, Jonas Thörnvall wrote:
> > > <snip>
> > > > var inputs = midi.inputs.values();
> > > > 
> > > > Is midi.input.values(); a function or a method?
> > > 
> > > There are no methods in JS, only functions, in fact closures.
> > > Then there are objects with properties, not attributes.
> > > 
> > > Those properties, just like variables, can hold any value, including
> > > references to functions (again, to closures), e.g.:
> > > 
> > > myobj.func = function () { return dosomething(); };
> > > 
> > > > How do i know the difference?
> > > 
> > > RTFM?  JS is notoriously the world's most misunderstood programming language
> > > ever, OTOH a language spec as well as some good enough tutorials are not
> > > that difficult to find really:
> > > 
> > > <https://developer.mozilla.org/bm/docs/Web/JavaScript>
> > > 
> > > > my.balls=jump
> > > > 
> > > > I can't track down the meaning within the code?
> > > 
> > > You cannot track the meaning of anything in that sense, i.e. by just
> > > considering the rules of the language: readability (which includes
> > > readable meaningfulness), just as correctness, is something we *strive*
> > > for...
> > 
> > But should one not be able to differentiate a function from a variable or
> > from a listener. A value allocation from a function call?
> 
> Not just by the name unless the programmer is using proper conventions, and
> even then one should be careful when reviewing code, as generally very few
> programmers can write decent code, but even the good programmers make
> mistakes and are subject to fatigue.
> 
> > Is this a value allocation or a function call.
> > 
> > my.balls=jump;
> 
> That is an *assignment*, dumbass.  RTFM.
> 
> *Plonk*
> 
> Julio

Really?????? Are you sure then why the fuck are there functions that never been called using those names?

input.onmidimessage = echoMIDIMessage;
input.value.onmidimessage = onMIDIMessage; 


If so why are there functions with those names?

function onMIDIMessage (message) {
  midiToOutPort(message);
}

function echoMIDIMessage( event ) {
  if (output) {
    output.send( event.data, event.timestamp );
  }
}


eatmy.balls=dumbass

[toc] | [prev] | [next] | [standalone]


#34478

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-06 05:28 -0800
Message-ID<3d1777d9-6756-4295-9d07-1f70f48d9e71@googlegroups.com>
In reply to#34477
Den lördag 6 januari 2018 kl. 14:26:27 UTC+1 skrev Jonas Thörnvall:
> Den lördag 6 januari 2018 kl. 13:24:58 UTC+1 skrev Julio Di Egidio:
> > On Saturday, January 6, 2018 at 12:39:55 PM UTC+1, Jonas Thörnvall wrote:
> > > Den lördag 6 januari 2018 kl. 12:25:13 UTC+1 skrev Julio Di Egidio:
> > > > On Saturday, January 6, 2018 at 11:23:16 AM UTC+1, Jonas Thörnvall wrote:
> > > > <snip>
> > > > > var inputs = midi.inputs.values();
> > > > > 
> > > > > Is midi.input.values(); a function or a method?
> > > > 
> > > > There are no methods in JS, only functions, in fact closures.
> > > > Then there are objects with properties, not attributes.
> > > > 
> > > > Those properties, just like variables, can hold any value, including
> > > > references to functions (again, to closures), e.g.:
> > > > 
> > > > myobj.func = function () { return dosomething(); };
> > > > 
> > > > > How do i know the difference?
> > > > 
> > > > RTFM?  JS is notoriously the world's most misunderstood programming language
> > > > ever, OTOH a language spec as well as some good enough tutorials are not
> > > > that difficult to find really:
> > > > 
> > > > <https://developer.mozilla.org/bm/docs/Web/JavaScript>
> > > > 
> > > > > my.balls=jump
> > > > > 
> > > > > I can't track down the meaning within the code?
> > > > 
> > > > You cannot track the meaning of anything in that sense, i.e. by just
> > > > considering the rules of the language: readability (which includes
> > > > readable meaningfulness), just as correctness, is something we *strive*
> > > > for...
> > > 
> > > But should one not be able to differentiate a function from a variable or
> > > from a listener. A value allocation from a function call?
> > 
> > Not just by the name unless the programmer is using proper conventions, and
> > even then one should be careful when reviewing code, as generally very few
> > programmers can write decent code, but even the good programmers make
> > mistakes and are subject to fatigue.
> > 
> > > Is this a value allocation or a function call.
> > > 
> > > my.balls=jump;
> > 
> > That is an *assignment*, dumbass.  RTFM.
> > 
> > *Plonk*
> > 
> > Julio
> 
> Really?????? Are you sure then why the fuck are there functions that never been called using those names?
> 
> input.onmidimessage = echoMIDIMessage;
> input.value.onmidimessage = onMIDIMessage; 
> 
> 
> If so why are there functions with those names?
> 
> function onMIDIMessage (message) {
>   midiToOutPort(message);
> }
> 
> function echoMIDIMessage( event ) {
>   if (output) {
>     output.send( event.data, event.timestamp );
>   }
> }
> 
> 
> eatmy.balls=dumbass

Since you say they are assignments and not function calls, what are they doing?
input.onmidimessage = echoMIDIMessage; 
input.value.onmidimessage = onMIDIMessage; 
eatmy.balls=dumbass;

[toc] | [prev] | [next] | [standalone]


#34479

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-01-06 05:34 -0800
Message-ID<59232e27-7a7b-40ff-9c37-fb522604f352@googlegroups.com>
In reply to#34478
Den lördag 6 januari 2018 kl. 14:28:50 UTC+1 skrev Jonas Thörnvall:
> Den lördag 6 januari 2018 kl. 14:26:27 UTC+1 skrev Jonas Thörnvall:
> > Den lördag 6 januari 2018 kl. 13:24:58 UTC+1 skrev Julio Di Egidio:
> > > On Saturday, January 6, 2018 at 12:39:55 PM UTC+1, Jonas Thörnvall wrote:
> > > > Den lördag 6 januari 2018 kl. 12:25:13 UTC+1 skrev Julio Di Egidio:
> > > > > On Saturday, January 6, 2018 at 11:23:16 AM UTC+1, Jonas Thörnvall wrote:
> > > > > <snip>
> > > > > > var inputs = midi.inputs.values();
> > > > > > 
> > > > > > Is midi.input.values(); a function or a method?
> > > > > 
> > > > > There are no methods in JS, only functions, in fact closures.
> > > > > Then there are objects with properties, not attributes.
> > > > > 
> > > > > Those properties, just like variables, can hold any value, including
> > > > > references to functions (again, to closures), e.g.:
> > > > > 
> > > > > myobj.func = function () { return dosomething(); };
> > > > > 
> > > > > > How do i know the difference?
> > > > > 
> > > > > RTFM?  JS is notoriously the world's most misunderstood programming language
> > > > > ever, OTOH a language spec as well as some good enough tutorials are not
> > > > > that difficult to find really:
> > > > > 
> > > > > <https://developer.mozilla.org/bm/docs/Web/JavaScript>
> > > > > 
> > > > > > my.balls=jump
> > > > > > 
> > > > > > I can't track down the meaning within the code?
> > > > > 
> > > > > You cannot track the meaning of anything in that sense, i.e. by just
> > > > > considering the rules of the language: readability (which includes
> > > > > readable meaningfulness), just as correctness, is something we *strive*
> > > > > for...
> > > > 
> > > > But should one not be able to differentiate a function from a variable or
> > > > from a listener. A value allocation from a function call?
> > > 
> > > Not just by the name unless the programmer is using proper conventions, and
> > > even then one should be careful when reviewing code, as generally very few
> > > programmers can write decent code, but even the good programmers make
> > > mistakes and are subject to fatigue.
> > > 
> > > > Is this a value allocation or a function call.
> > > > 
> > > > my.balls=jump;
> > > 
> > > That is an *assignment*, dumbass.  RTFM.
> > > 
> > > *Plonk*
> > > 
> > > Julio
> > 
> > Really?????? Are you sure then why the fuck are there functions that never been called using those names?
> > 
> > input.onmidimessage = echoMIDIMessage;
> > input.value.onmidimessage = onMIDIMessage; 
> > 
> > 
> > If so why are there functions with those names?
> > 
> > function onMIDIMessage (message) {
> >   midiToOutPort(message);
> > }
> > 
> > function echoMIDIMessage( event ) {
> >   if (output) {
> >     output.send( event.data, event.timestamp );
> >   }
> > }
> > 
> > 
> > eatmy.balls=dumbass
> 
> Since you say they are assignments and not function calls, what are they doing?
> input.onmidimessage = echoMIDIMessage; 
> input.value.onmidimessage = onMIDIMessage; 
> eatmy.balls=dumbass;

Are you telling me echoMIDIMessage and onMIDIMessage are variables? If so where the fuck did they come from? And why would you assign a null variable to an input port? Or are they functions assigned to a port. 

You said they are assignments YES or NO?

[toc] | [prev] | [next] | [standalone]


Page 1 of 4  [1] 2 3 4  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web