Le 26/02/2013 20:50, Mounir Lamouri a écrit :
> On 25/02/13 13:14, David Bruant wrote:
>> Hi,
>>
>> [...]
>>
>> Proposal:
>> 1) Abstract remote as async
>> 1.1) Whenever an API has a property which is not genuinely local, add a
>> get*() method which returns a DOMRequest (or hopefully soon a DOMFuture
>> [6])
> We thought a lot about that and we decided that there was no interest to
> make the Battery API asynchronous because it would add a level of
> complexity for developers that seems useless.
You skipped that part, but I wrote "This also makes reviewing app
performance harder, because what doesn't look like a bottleneck (getting
properties out of an object) may just be one.".
Saying that getting a property is easier is a biased argument. Of course
the one-liner and the post on hacks.m.o are sexier this way, but when
your code is already hundreds of lines long, the difference between:
var freq = radio.frequency
// play with freq
and
radio.getFrequency().then(function(freq){
// play with freq
})
is blurred away.
You likely copy/pasted the code to get the frequency from MDN or the
gaia app or a prevous app anyway. Pragmatically speaking, this kind of
difference in APIs is negligeable when writing an app, mostly because
your focus is building the UI.
Also, if developer ease is the cause, why the asymmetry between getting
(sync&blocking) and setting (async)?
Rehashing previous arguments (that you skipped too!), but localStorage
was also designed with developer convenience in mind and a lot are
throwing rocks at it now, especially at Mozilla (see links in the
previous post). We should learn from history instead of reiterating it.
> Generally speaking, the question isn't as simple as "this information
> can take time to be retrieved so we should make it async", it is a
> balance between ease for developers and ability for user agents to make
> the information virtually synchronous.
Why not expose both versions as it is done in Node.js enabling the best
of both worlds?
People who want to draft something quickly use the sync blocking
version, people who don't want their startup time.
>> 2) Improve *change events to carry the modified value.
>> Currently, to get the new frequency, one has to do:
>>
>> navigator.FMRadio.addEventListener('frequencychange', function(e){
>> // nothing useful in the 'e' argument +
>> var freq = navigator.FMRadio.frequency; // blocking IPC :-s
>> });
> You are pointing a bug, not a problem in the API. as soon as an event is
> sent because there is a frequency chance, calling
> navigator.FMRadio.frequency should be fast and shouldn't do IPC calls.
I'm pointing 2 things. The blocking IPC call is halfway between an
implementation and API bug.
Not carrying the modified value in the event is a pure API bug. You
skipped that part from my previous post:
"When I listen to the 'frequencychange' event, I rarely only want to be
notified. I mostly care about the new value."
> Indeed, this is how some API work (like DeviceSensors) but they are
> different because the API is all about events (you can't do
> navigator.sensors.foo). FWIW, I do not really like that.
> The Battery API was weirdly designed and very close to that in the past
> and the hassle it would have been to use it wouldn't have worth it.
In my opinion, your sentence "FWIW, I do not really like that" captures
the essence of the debate we're having.
I'll spend some time on that here, because I feel it is and will be at
the heart of any API debate we will be having. I'll answer to you
because you wrote the words, but I don't mean to singularize you as a
person since I know you're not the only one thinking this way. Whenever
I'll write "you", it'll be less about you as a person than you as a C++
hacker.
Alex Russel wrote something very interesting about WebIDL a couple of
months ago [1] where he opposes those who write the JavaScript API specs
(who he describes as "C++ hackers") and those who use these APIs ("JS
developers").
Very much like natural languages, users of programming languages carry a
cultural bagage. What's easy to express in a language is not in another.
Some idioms of a language don't exist in another. Very much like natural
languages, if you only practice one language, reading another language
is complicated, very often less because of the very words, but more
because of the idioms, the culture around the language.
We'd love to think that we communicate after we think, but the opposite
is much more true: languages shape how we think. While in French, "on
prend une décision" ("one takes a decision"), like one chooses a path to
follow among a limited handful of choices, in English, "one makes a
decision", building it out of a combination of decision lego-like
pieces. The language we use shape how we think, shapes the culture of
the groups of people who use and work around the same language.
When I read your "FWIW, I do not really like that", what I understand is
"this is not how I do that in my culture and this is making me feel
uncomfortable". Just to be clear, I do not mean to blame you or point a
finger at you; I'm just sharing a feeling.
In my "culture" (JS devs), you have no idea how much I am happy with the
DeviceSensors and events all over the place. Values aren't stuck to a
given objects. Values fly around and I catch them by setting functions
here and there. The event loop protects me from race conditions (having
done some C in my life, this property has some gold to it). This API
fits how I use JavaScript very well.
2 other people from the JS culture (Julien and Rick) agreed that having
the changed value in the event is the natural way to do it. I feel
cultural bias should be put aside and this feedback should be heard.
> FWIW, that discussion already happened (a few times likely) in the DAP
> WG and the DAP WG would be the best place to ask for changes.
Are both cultures properly represented? ;-)
I'll post my concerns on the DAP WG list.
> I would recommend you to read the archives before though.
I will.
David
[1]
http://lists.w3.org/Archives/Public/public-script-coord/2012OctDec/0122.html