March 03, 2012
On 03/03/2012 12:12, Jacob Carlborg wrote:
> On 2012-03-02 15:57, Adam D. Ruppe wrote:
>> On Friday, 2 March 2012 at 09:33:44 UTC, Alix Pexton wrote:
>>> Have you considered faking scopes in JS using anonymous functions?
>>
>> Yeah, though right now I'm trusting the D compiler to
>> keep it straight, and it is doing a pretty good job
>> while being really simple to code.
>>
>> What happens is all the local variables are mangled
>> with respect to their full scope too (which leads to
>> ridiculously long, but unique names).
>
> Wouldn't you save a lot of characters by properly scoping the variables
> instead of using unique names? The compile JavaScript code would also be
> more readable.
>

and potentially faster!

A...
March 03, 2012
On 2012-03-02 19:13, Nick Sabalausky wrote:
> "Jacob Carlborg"<doob@me.com>  wrote in message
> news:jiptfu$qrg$1@digitalmars.com...
>> On 2012-02-29 18:46, Nick Sabalausky wrote:
>>> "Alex Rønne Petersen"<xtzgzorex@gmail.com>   wrote in message
>>> news:jilnie$1fsr$1@digitalmars.com...
>>>> On 29-02-2012 18:32, Andrei Alexandrescu wrote:
>>>>> On 2/26/12 9:51 PM, Adam D. Ruppe wrote:
>>>>>> https://github.com/downloads/adamdruppe/dtojs/dtojs.zip
>>>>> [snip]
>>>>>
>>>>> That's interesting. So the idea is to make an entire subset of D
>>>>> convertible to Javascript?
>>>>>
>>>>> What use cases do you have in mind?
>>>>>
>>>>>
>>>>> Andrei
>>>>>
>>>>
>>>> Avoiding writing JS directly in web apps comes to mind.
>>>>
>>>
>>> Yea, creating JS without having to actually *write* JS is a huge use-case
>>> in
>>> and of itself.
>>>
>>> (I still can't believe the web has standardized on such an absolute shit
>>> langauge. Hell, two of them if you count PHP on the server.)
>>
>> Five if you count HTML, CSS and SQL as well.
>>
>
> Very true, but a far as shittiness goes, JS and PHP are in a whole other
> league (IMO).

Yeah, I agree. I'm just saying, thank god I don't have to use PHP in my job. I'm using CoffeeScript instead of JavaScript whenever I can which makes it a bit more bearable. Yes I know many people here don't like CS, specially the syntax, but it fixes several of the most annoying things about JS.

> Actually, HTML/CSS for what they are - *document* description formats -
> really aren't all that bad. The only real *major* problem with HTML/CSS is
> not the formats themselves, but the fact that people keep abusing them as
> application presentation layers, which they clearly aren't and were never
> intended to be. (And basing an entire application around the
> deliberately-stateless HTTP? Seriously? WTF?)
>
> Latex isn't bad (from what little I've seen), but if people started
> pretending it was a presentation layer for programs, then yea, it would
> completely blow for that. But that's exactly what people did with HTML/CSS.
> So HTML and CSS get a bad reputation when really the true blame lies with
> the people pushing for their misuse. (Not that HTML/CSS couldn't be improved
> even as pure document formats.)

Yes, I think both HTML and CSS could be improved a lot. One of the most annoying things is there's no good way to handle scoping. SASS (regardless of which syntax you choose to use) makes this problem less annoying and fixes several other issues with CSS. The fact that you most likely uses a server side language to output HTML fixes many of the problems with HTML.

-- 
/Jacob Carlborg
March 03, 2012
On 2012-03-03 06:56, Nick Sabalausky wrote:
> "Adam D. Ruppe"<destructionator@gmail.com>  wrote in message
> news:sazpaicrjwzchqcfwlql@forum.dlang.org...
>> On Friday, 2 March 2012 at 18:28:15 UTC, Nick Sabalausky wrote:
>>> Suggestion: Allow all D features even if it
>>> requires...inefficient-er...boilerplate, BUT then have a system [...]
>>
>> Eh. A problem there is those pragmas or whatever would be
>> unrecognized by the real dmd. A command line switch, maybe,
>> though.
>>
>
> I thought unrecognized pragmas were supposed to just be ignored? (Or maybe I
> have it backwards?)
>
>

No, they're not:

"Compilers must diagnose an error for unrecognized Pragmas, even if they are vendor specific ones. This implies that vendor specific pragmas should be wrapped in version statements".

http://dlang.org/pragma.html

-- 
/Jacob Carlborg
March 03, 2012
"Jacob Carlborg" <doob@me.com> wrote in message news:jit2r7$rlu$2@digitalmars.com...
>> I thought unrecognized pragmas were supposed to just be ignored? (Or
>> maybe I
>> have it backwards?)
>>
>>
>
> No, they're not:
>
> "Compilers must diagnose an error for unrecognized Pragmas, even if they are vendor specific ones. This implies that vendor specific pragmas should be wrapped in version statements".
>
> http://dlang.org/pragma.html
>
> -- 
> /Jacob Carlborg

There's a switch to ignore them.


March 03, 2012
On Saturday, 3 March 2012 at 12:12:53 UTC, Jacob Carlborg wrote:
> Wouldn't you save a lot of characters by properly scoping the variables instead of using unique names?

There's no such thing as proper scoping in Javascript.

The next best thing is the nested functions, but that's
really just trading one poison for another.


D mangled names do a lot more than scoping, too, anyway.
Mangled names overload properly:

void a(int, int);
void a(int, string);

a(1, "one"); // which one gets called?


With dmd's name mangling, it Just Works.


Now, there might be something to gain by using prettier
local variable names, but it is a lot of extra work and
IMO the benefit is still very small.


Note that local variables are still local variables
95% of the time (and the other 5% is a bug that I'm
hoping to fix today), so its already scoped almost
as well as it can be on the function level.



The biggest benefit is readability and size. Size is handled
by running it through a string replacer (tools/mangledown.d).

Readability is a nice gain, but not an essential one I think;
it is readable right now if you want to.
March 03, 2012
On Saturday, 3 March 2012 at 12:10:47 UTC, Jacob Carlborg wrote:
> No, we don't want to do it like Dart:
> 17260 lines of code for Hello World.

Wow. I thought I was a bit on the bloated side with
~100 lines of boilerplate (before running the unused
function stripper).

$ ../dmd -md object.d
DMD v2.058 DEBUG
$ wc object.js
  108   472 11843 object.js



Then again, when giant things like jQuery is considered
a "necessity" when I get by just fine with my 10 KB
(source, not minified, not gzipped) custom library,
if even that, it shows there's a big disconnect between
me and most other web people nowadays.
March 03, 2012
On Saturday, 3 March 2012 at 16:29:25 UTC, Adam D. Ruppe wrote:
> There's no such thing as proper scoping in Javascript.

Let me expand a bit. consider this D:

if(1) {
    int a = 3;
}

In JS, right now, that'd output:

if(1) {
    var mangled_a = 3;
}

which, to the interpreter, is:

var mangled_a;
if(1) {
    mangled_a = 3;
}

thanks to declaration hoisting.


If you want it to be scoped literally like D,
it'd look more like this:

if(1) {
   function() {
      var a = 3;
   }();
}


I really doubt that'd help performance. Another option
is to reuse declarations:

if(1) {
  int a = 0;
}
string a = "";

could become:

var a;
if(1) {
   a = 0;
}
a = ""; // we know the old a is out of scope, so we'll reuse it


but I don't see a big benefit there either. Now, the JS
compiler will definitely see a as a dynamically typed var,
and may not be able to do the same optimizations it could
if it had a consistent type.


When you consider the bug-pronedness of me doing this instead
of relying on dmd's well debugged mangling process to do it
all for me, I really think it is a net loss, despite the
slightly more readable names.



Oh another thing: global variables in D are module scoped.
The mangledness again handles that for me. Just another
bug opportunity.



Perhaps a smarter helper tool could make pretty names, but
I don't want to put it in the compiler.
March 03, 2012
On 2012-03-03 17:29, Adam D. Ruppe wrote:
> On Saturday, 3 March 2012 at 12:12:53 UTC, Jacob Carlborg wrote:
>> Wouldn't you save a lot of characters by properly scoping the
>> variables instead of using unique names?
>
> There's no such thing as proper scoping in Javascript.
>
> The next best thing is the nested functions, but that's
> really just trading one poison for another.

Ok, I see.

> D mangled names do a lot more than scoping, too, anyway.
> Mangled names overload properly:
>
> void a(int, int);
> void a(int, string);
>
> a(1, "one"); // which one gets called?
>
>
> With dmd's name mangling, it Just Works.

Well, functions are different.

> Now, there might be something to gain by using prettier
> local variable names, but it is a lot of extra work and
> IMO the benefit is still very small.
>
>
> Note that local variables are still local variables
> 95% of the time (and the other 5% is a bug that I'm
> hoping to fix today), so its already scoped almost
> as well as it can be on the function level.
>
>
>
> The biggest benefit is readability and size. Size is handled
> by running it through a string replacer (tools/mangledown.d).
>
> Readability is a nice gain, but not an essential one I think;
> it is readable right now if you want to.


-- 
/Jacob Carlborg
March 04, 2012
On 4 March 2012 05:40, Adam D. Ruppe <destructionator@gmail.com> wrote:
> On Saturday, 3 March 2012 at 12:10:47 UTC, Jacob Carlborg wrote:
>>
>> No, we don't want to do it like Dart:
>> 17260 lines of code for Hello World.
>
>
> Wow. I thought I was a bit on the bloated side with
> ~100 lines of boilerplate (before running the unused
> function stripper).
>
> $ ../dmd -md object.d
> DMD v2.058 DEBUG
> $ wc object.js
>  108   472 11843 object.js
>
>
>
> Then again, when giant things like jQuery is considered
> a "necessity" when I get by just fine with my 10 KB
> (source, not minified, not gzipped) custom library,
> if even that, it shows there's a big disconnect between
> me and most other web people nowadays.

Hmm, does your DOM library compile with this? Also, is it smaller than jQuery? And how easy would it be to make it work with the browser dom?

This is mostly because I pretty much use jQuery for AJAX and Dom manipulation, everything is just extras.

--
James Miller
March 04, 2012
On 3/3/12, Adam D. Ruppe <destructionator@gmail.com> wrote:
> Oh another thing: global variables in D are module scoped.

Could export help?