March 01, 2012
On 2012-03-01 19:56, Alex Rønne Petersen wrote:
> On 01-03-2012 19:04, Ary Manzana wrote:
>> 3. With JS you don't have to compile and run your code (well, I guess
>> you could make something smart in D for that).
>
> ? The D -> JS converter just translates it. It's no different from
> running e.g. the CoffeeScript compiler.

It's quite a difference. The semantics of CoffeeScript and JavaScript is more alike than D and JavaScript. CoffeeScript was created to be compile to JavaScript, not something you could say about D.

>> 4. If you write JS you can debug it in the browser. No need to track
>> back to the original source code.
>
> Valid argument. Maybe we can make the D -> JS converter help in some way
> here?

Similar problem with CoffeeScript, not as bad as with D since it outputs readable JavaScript.

>> 5. If you don't like JS syntax or verbosity, you can use CoffeeScript,
>> which is just a syntax rewriter, not a language/paradigm shift:
>> http://coffeescript.org/
>
> Don't even get me started on the horrible "features" in CoffeeScript.
> The guy who wrote the language literally had no clue what he was doing
> (he admitted to reading some "make your own language" book), and it
> isn't much better than JavaScript in terms of odd behavior and weird
> design decisions.

It's way way WAY more better than JavaScript.

* Class based object model
* Function binding, language support for binding the this reference

If CoffeeScript had only these two features it would be so much more useful than JavaScript, but it has a lot more:

* Extremely short function/lambda syntax
* Built-in loop comprehension
* == behaves as you would expect
* Existential operator
* Default arguments
* Variadic arguments
* Object syntax
* foreach loop that actually makes sense
* Almost everything is an expression
* No need to declare variables
* Implicit returns
* No need for semicolons (yeah, I know JS have this as well but most don't seem to use this feature)
* Ranges
* Arrays slicing

>> 6. Javascript objects have some built-in properties that are different
>> from D. So implementing those in D would make their performance worse
>> (but you can always hard-code those functions into the compiler and
>> translate them directly to their JS equivalent).
>
> Can you be a little more specific here?
>
>>
>> The good thing about writing in D is that you could probably get some
>> IDE for autocompletion and such. You might also like to type things
>> instead of using dynamic types.
>
> To be fair, excellent JS IDEs exist already; Visual Studio has great JS
> auto-completion, and ReSharper enhances it a lot too.
>


-- 
/Jacob Carlborg
March 01, 2012
I've played with gdc, but it's pretty complicated. I have few ADM 5120 routers with debwrt and it would be nice to be able compile D2 code there, but so far, it was just fail.

C run pretty much everywhere and metacompiler D2C would be nice..

On 1.3.2012 09:05, Daniel Murphy wrote:
> "Bystroushaak" <bystrousak@kitakitsune.org> wrote in message news:mailman.239.1330541205.24984.digitalmars-d-announce@puremagic.com...
>> Thx.
>>
>> On 29.2.2012 18:03, Robert Clipsham wrote:
>>> On 29/02/2012 16:56, Bystroushaak wrote:
>>>>> Daniel Murphy's microd fork of dmd, meant to output C
>>>>
>>>> Link please.
>>>
>>> https://github.com/yebblies/dmd/tree/microd
>>>
> 
> Don't get your hopes up, it was more of an experiment than a serious fork, I have no intention of doing anything more with it (unless I get really bored again).  It does work, but the effort is probably better spent on improving gdc's support of embedded platforms.
> 
> 
March 01, 2012
On Thursday, 1 March 2012 at 19:49:46 UTC, Bill Baxter wrote:
> Might TypedArrays help you implement some number type semantics?

Yeah, I think so. I do have compatibility concerns though;
it'd be a pity of something taking a ubyte means it doesn't
work in IE8 anymore.

I'll have to play with it though.
March 02, 2012
"Bystroushaak" <bystrousak@kitakitsune.org> wrote in message news:mailman.281.1330632834.24984.digitalmars-d-announce@puremagic.com...
> I've played with gdc, but it's pretty complicated. I have few ADM 5120 routers with debwrt and it would be nice to be able compile D2 code there, but so far, it was just fail.
>
> C run pretty much everywhere and metacompiler D2C would be nice..
>

I think once you get past the horror that is building gcc for your target platform, the big issue remaining is that druntime needs to be ported. You'll hit the same issue with a D->C translator, so it might be better just to work on the actual runtime.  Doing a proper gdc-based compiler should get you some other nice things, like platform specific attributes/versions, inline asm, and a better debugging experience.


March 02, 2012
On Thursday, 1 March 2012 at 08:01:07 UTC, Daniel Murphy wrote:
> Web programming... might actually become non-horrible?

hehe. I already found it ok though; I've been using
D on the server for... will be two years in a couple
weeks.

Javascript isn't bad if you use it sparingly, and
in the last year, my web.d server side thing has just
enough javascript to let me write less of it.

I just call server side functions in most the JS. I
went a little nuts on partial application to make it
nice looking; you pass arguments to the callback when
you make it.



But, it is nice to have this other stuff too. If I
have to do a browser game, definitely doing D now,
from top to bottom. Work wants ipad apps too...
I'll probably do them as downloadable browser things,
now in D!




Anyway, a few more hours on d to js today. I spent
the time working on struct semantics.


It is amazing how complicated structs are! Compared
to this, classes are just plain easy.


My tests file (which I need to run in real D to confirm
my thought here, but I think all my asserts are sane)
now passes including tests of struct.

http://arsdnet.net/dtojs/tests.d



I implement structs as Javascript Object()'s, but this
doesn't quite match what D expects.

1) JS Object are references, whereas D struct are value.
2) JS variables have indeterminate lifetimes
3) The JS language doesn't have block scoping like D.



(1) was a big mess, and I'm sure I don't have it right
yet (I know it is a lot less efficient than it could be).

My solution was to make all assignments do shallow copies,
including function call.

void t(MyStruct a) {}
t(a);

becomes

t(__d_struct_copy(a))


Worked for the basics. But, D structs are incredibly
complex monsters.

opAssign, postblit, copy constructors, blit initializers,
expression initializers, TOKconstruct - something I'm not
even sure what it actually is.

Well, I think I got it. Lots of filthy dirty code, but
it passed the test file.

I haven't tested struct constructors yet, but they are
relatively easy, just like class constructor, so I'm
confident it will work.



(2) and (3) go together: variable lifetime. D structs
die when they go out of scope, both on function
returns and exceptions.

dmd implemented this as a Scope followed by a Finally.

I ended up making it put try {} around the scope, and then
write out the finally {}.

dmd really did all the work already! And... finally works
in Javascript.


Amazing, we have struct destructors working like you expect.
Moreover, dmd implements scope(exit) the exact same way.

Boom, we have scope guards too.


To my surprise, scope(failure) and scope(success) Just Worked:
dmd set up a flag variable and automatically added it to
the appropriate places.


As far as I can tell, we have variable lifetime! (JS's garbage
collector is still a question, and some of the variables are
global - dmd loves the (var a, b) syntax, which is invalid so
I made var a in global scope. It is not set to null when done.)



Pretty cool. The majority of the language works correctly,
though there's a few hacks in there to make it happen.


I probably won't upload another zip until the weekend though.
March 02, 2012
This will go nicely with the web framework I'm building in D. I'm borrowing heavily from silverlight. Here's a teaser (sorry, neglected to comment the code...)

Here's a sample code file (CGI script for apache, I'm new to these web technologies):
http://pastebin.com/SpfmfpmS

and here's what the resulting site looks like, sorry for the image quality

before pressing the button:
http://i.imgur.com/JGvMC.png
after:
http://i.imgur.com/9ZiQp.png
Notice how I clicked a different tab (woot)

It's my first time using HTML, CSS, or JS, so it's a bit rough. But I learn it as I go along, to perform the code generation.

A whole lot of really neat CTFE and mixins went into having the Control classes and Factory working as smoothly as they do. I'll publish it on my blog once it's built (I want to showcase darklight with a blog written in darklight) :D

But I just noticed you have a whole suite of D web code, I'll have to look into it.

Thanks for all the hard work you've put into D, it's quite a feat.
March 02, 2012
"Ary Manzana" <ary@esperanto.org.ar> wrote in message news:jiodnj$ric$1@digitalmars.com...
>
> I think it's cool you can convert D to JS, but I don't see why anyone would want to do it.
>
> 1. JS is a superior language: variables are dynamic and are not bound to
> just one single type during their lifetime. JS objects can store any
> property.
> 2. JS funcions are much easier to write (no need to declare types) and
> also to pass around (no need to write "&").

Are you insane or just masochistic? ;)

> 3. With JS you don't have to compile and run your code (well, I guess you could make something smart in D for that).

Meh. I've done a lot of web work where "no compile" is common, and I've never seen it as really being that big of a deal (unless you're using something like C++ that takes ages to compile). It's an overrated selling point of such langauges, IMO, much like "Our langauge doesn't require semicolons!" Meh, so what? Trivialities.

> 4. If you write JS you can debug it in the browser. No need to track back to the original source code.

Not a bad point. Although Adam's suggestion does help mitigate it.

> 5. If you don't like JS syntax or verbosity, you can use CoffeeScript, which is just a syntax rewriter, not a language/paradigm shift: http://coffeescript.org/

Bleh. I hate JS with a passion and I'd still much rather use straight JS than CoffeeScript. CoffeeScript has a few nice bits of sugar, but the basic syntax is just plain horrid. At least plain JS doesn't have that indent-syntax abomination that's so popular these days.

> 6. Javascript objects have some built-in properties that are different from D. So implementing those in D would make their performance worse (but you can always hard-code those functions into the compiler and translate them directly to their JS equivalent).
>

If you're doing any non-trivial JS, you can *expect* it to be slow, period. This is like saying "I drive a $100k sports car with 600 horsepower and yet I care about my gas mileage". Just kinda goofy.


March 02, 2012
"Adam D. Ruppe" <destructionator@gmail.com> wrote in message news:uvagboafiyjrhvywpiyd@forum.dlang.org...
>
> but I'd rather than an error than it generating
> horribly inefficient javascript for simple operations.
>

You make it sound as if there's another kind of JS.


March 02, 2012
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.

-- 
/Jacob Carlborg
March 02, 2012
On 2012-03-02 03:28, Adam D. Ruppe wrote:
> On Thursday, 1 March 2012 at 08:01:07 UTC, Daniel Murphy wrote:
>> Web programming... might actually become non-horrible?
>
> As far as I can tell, we have variable lifetime! (JS's garbage
> collector is still a question, and some of the variables are
> global - dmd loves the (var a, b) syntax, which is invalid so
> I made var a in global scope. It is not set to null when done.)

What do you mean with "dmd loves the (var a, b) syntax, which is invalid so"?

-- 
/Jacob Carlborg