On Sunday, October 20, 2013 8:33:40 PM UTC-7, Lex Berezhny wrote: > > On Sun, Oct 20, 2013 at 10:24 PM, Sarvi Shanmugham > <sarv...@gmail.com<javascript:> > > wrote: > >> Question 1: >> The simple i=i*2 seems to have a complex translation. Can't it just >> be i=i*2 in java script and handle the error when it happens? >> > > Python allows you to overload the multiplication operator. We have to > check at runtime if the objects being multiplied have overloaded > multiplication. > > Also, native strings in Python overload the multiplication operator, > that's why you can do: > > print '='*10 > I get this. But considering Javascript is JITed and highly optimized including unrolling static loops and function calls if I understand right, wouldn't the following i=p.op_mul(i,2) be faster than the current i = (typeof ($mul1=i)==typeof ($mul2=2) && typeof $mul1=='number'? $mul1*$mul2: $p['op_mul']($mul1,$mul2)); as long as op_mul() can handle numbers as well? And much more readable too?
> > >> Question 2: >> The whole idea of using dictionaries to store functions seems >> inefficient for access. Is there an alternative approach using say >> prototype.bin() or other approaches to define and access these functions >> that people have tried? >> > > In javascript objects/dictionaries are one and the same, so one can't be > more efficient than the other. > > >> a = {} > Object {} > >> a.foo = 3 > 3 > >> a['foo'] > 3 > Yeah, thats sorta why I asked the question. Just a beginnner but this how I understood java script objects and classes and I thought this entire generated code segmented would have a been much more readable as objects instead of dictionary objects. And whats with the $ notation. From what I am reading this is just jQuery convention and not required. I presume we do pyjamas because we love python and hence readable code. Yet the generated Javascript seems less so, though from what I understand there more readable alternatives. So was just trying to understand what the thinking was. > If you want to hack on pyjs internals you're definitely going to have to > learn JavaScript. > Yup. Pretty much what I have been doing right now. :-) Still much ways to go. Sarvi: PS: Has this blog post been discussed on the list. Did any changes/action items come out of it? > > - lex > -- --- You received this message because you are subscribed to the Google Groups "Pyjs.org Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to pyjs-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.