January 15, 2015
On Thursday, 15 January 2015 at 07:58:47 UTC, Andrei Alexandrescu wrote:
> On 1/14/15 7:19 PM, brian wrote:
>> My point was that there are fewer examples of *how* to do things in D.
>> This will discourage the new user, which will prevent it becoming a more
>> popular language.
>
> Yes, it would be great if we could crowdsource a cornucopia of "how to" topics in D. -- Andrei

D is the 8th most popular language on Rosetta Code(I think most of the entries are from a single person - Bearophile), it's within ~25 entries of C, Ruby, etc.

There's also the cookbook on the wiki that's unfinished.
http://wiki.dlang.org/Cookbook
and the tutorial page
http://wiki.dlang.org/Tutorials
January 15, 2015
On Tuesday, 13 January 2015 at 23:34:40 UTC, brian wrote:
> A question first: ... what do people actually have working in D?
> I find very few "working examples" of things I want to do. Or things in general. That I can read and say "oooh that's close to what I want, I can tweak it a little here and there".
>
> Eg.
> I want a program to write tweets.
> I can't just google "twitter example d" and find a nice starter program to connect a write a tweet.

if you google "dlang" "twitter api"
http://code.dlang.org/packages/twitter4d is the second result.
January 15, 2015
Look at the curves for referring domains:

https://ahrefs.com/site-explorer/overview/subdomains/?target=www.dlang.org

https://ahrefs.com/site-explorer/overview/subdomains/?target=www.golang.org

https://ahrefs.com/site-explorer/overview/subdomains/?target=www.rust-lang.org

Rust has an impressive marketing trajectory there. But D is growing too.

(The backlinks graphs are misleading due to documentation pages etc.)
January 15, 2015
On Thursday, 15 January 2015 at 10:05:23 UTC, Ola Fosheim Grøstad wrote:
> Look at the curves for referring domains:
>
> https://ahrefs.com/site-explorer/overview/subdomains/?target=www.dlang.org
>

Actually, that was wrong since dlang does not use the "www" standard, that is much better:

https://ahrefs.com/site-explorer/overview/exact/?target=dlang.org
January 15, 2015
On Thursday, 15 January 2015 at 08:54:34 UTC, ponce wrote:
> On Thursday, 15 January 2015 at 03:19:10 UTC, brian wrote:
>>
>> My point wasn't that there aren't ways to do things in D.
>> My point was that there are fewer examples of *how* to do things in D.
>> This will discourage the new user, which will prevent it becoming a more popular language.
>> So if I'm looking for a new language to use, I'd probably stick to the ones that have more examples.
>
> Does this help? http://p0nce.github.io/d-idioms/

Just went through your list of idioms, noticed one mistake, anonymous _nested_ structs/unions are in D:

"anonymous structs/unions are allowed as members of other structs/unions"
http://dlang.org/struct.html
January 15, 2015
On Thursday, 15 January 2015 at 10:19:36 UTC, Joakim wrote:
> On Thursday, 15 January 2015 at 08:54:34 UTC, ponce wrote:
>> On Thursday, 15 January 2015 at 03:19:10 UTC, brian wrote:
>>>
>>> My point wasn't that there aren't ways to do things in D.
>>> My point was that there are fewer examples of *how* to do things in D.
>>> This will discourage the new user, which will prevent it becoming a more popular language.
>>> So if I'm looking for a new language to use, I'd probably stick to the ones that have more examples.
>>
>> Does this help? http://p0nce.github.io/d-idioms/
>
> Just went through your list of idioms, noticed one mistake, anonymous _nested_ structs/unions are in D:
>
> "anonymous structs/unions are allowed as members of other structs/unions"
> http://dlang.org/struct.html


Thanks! We were 2 to have missed that.
January 15, 2015
On Wednesday, 14 January 2015 at 10:45:17 UTC, Ola Fosheim Grøstad wrote:
> «twitcurl is a pure C++ library for twitter APIs. twitcurl uses cURL for handling HTTP requests and responses.»


I feel like I say this all the time.... but there's a twitter bit hidden in my misc. D modules, in oauth.d

https://github.com/adamdruppe/arsd/blob/master/oauth.d#L320

Call it:

tweet(twitter(apiKey, apiSecret), userToken, userSecret, "tweet message");

You can get the four tokens on dev.twitter.com, create an app then create your own access token. Plug them in and call the function:

https://twitter.com/adamdruppe/status/555738599069868033

It depends on curl.d, sha.d, and cgi.d from my repo.


You can also use oauth.d to retrieve tweets - use the tokens it provides for a call to curlOauth to the api function, then parse it with something like dom.d or jsvar.d (I think it gives XML but they might have changed that in the last year since I used it) and authorize users. Authorization is a bit tricky:

https://github.com/adamdruppe/arsd/blob/master/oauth.d#L343

and I don't have an example written up for them (I do, but it is in my closed source work projects so I'd have to clean it up before posting in public, I can do it later if you're interested), but you have to call step one, then step two when you get the answer to that. It will return the tokens. It assumes you're a web app using my cgi.d.
January 15, 2015
On Thursday, 15 January 2015 at 14:53:23 UTC, Adam D. Ruppe wrote:
> On Wednesday, 14 January 2015 at 10:45:17 UTC, Ola Fosheim Grøstad wrote:
>> «twitcurl is a pure C++ library for twitter APIs. twitcurl uses cURL for handling HTTP requests and responses.»
>
>
> I feel like I say this all the time.... but there's a twitter bit hidden in my misc. D modules, in oauth.d
>
> https://github.com/adamdruppe/arsd/blob/master/oauth.d#L320

Sounds like perfect topic for your newsletter? :)
January 15, 2015
On Thursday, 15 January 2015 at 14:57:48 UTC, Ola Fosheim Grøstad wrote:
> Sounds like perfect topic for your newsletter? :)

I could totally fill in the "project spotlight" with stuff from that repo for at least a year, not even kidding. But I don't want it to be all about me! (and oauth.d isn't new, i wrote that like three years ago... it had to be updated a while ago because twitter deprecated v1 of their api, but other than that, it hasn't changed much)

Over the years though, I've written a lot of D programs and do my own libs as required. I've done 2d games, working on a 3d game now, web applications with social media interop for authorization and posting, email marketing, email parsing, I've written a terminal emulator, taskbar, the list goes on and on.

And only about 1/3 of the D code I've written is even on Github! (Of course, about half of my D code is totally uninteresting, closed source business logic stuff, though it would make nice examples to how to use the libraries for real world tasks...)



Let me give an outline of the misc modules to give you an idea of how varied this is:

audio.d, screen.d, engine.d - my old game stuff, wrapping SDL, works in D1 and D2 (or at least did last time I tried it about a year ago). Soon to be replaced by the dependency-free simpledisplay.d, simpleaudio.d, joystick.d combo.

bmp.d, png.d - read/write for bmp and image files.
jpg.d - partial read support for jpeg headers (just to get the size of the image).

cgi.d - basic module for making web apps. Includes cgi, fastcgi, scgi, and an embedded http server. Reads url encoded data, MIME data (for file uploads on the web), and has full URL parsing, among other things.

characterencodings.d - stuff for converting other strings to UTF-8. Supports about twenty other encodings based on webpage and email mining I've done in the past. Also has a lossy conversion as a catchall.

color.d - a color struct for RGBA, also does CSS color string read/writing, HSL <-> RGB, some color manipulation, alpha blending, and image base classes including palette to true color and true color to palette (quantization).

csv.d - simple csv reader, predates std.csv (and is a bit simpler)

curl.d - wrapper for libcurl (predates std.net.curl)

database.d - base class for RDBMS access. Also includes basic ORM and query builder in the form of DataObject and SelectBuilder. It is a simple, low-level wrapper of sql so you can manipulate it semantically more easily but you still need to understand sql to use it. (It also doesn't limit your options!)

mysql.d, postgres.d, mssql.d, sqlite.d - drivers for database.d (wrapping C libraries)

dom.d - XML and HTML parsing and manipulation, including CSS selectors and other tools that can help for implementing a browser. API inspired by modern Javascript DOM, capable of scraping tag soup web pages.

email.d - functions for reading and writing emails with MIME attachments, html and text versions, character sets. Can scrape mbox format, I used it to automatically monitor and reply to some email addresses sitting on the smtp server.

english.d - printing numbers in English

eventloop.d - an epoll based event loop for responding to and sending events. My other modules can optionally tie into it, so you can have one event loop driving files, networks, terminals, X windows, and more.

html.d - stuff for html and CSS manipulation. Includes the Css Macro Expander, which is similar to functionality offered by SASS (also available as a stand alone dub package on code.dlang.org btw), and a Javascript macro expander which you can use to add stuff like foreach to that language. Also has HTML sanitization based on a full parser and whitelist.

htmltotext.d - converts html to plain text so you can display it in a terminal or an email, etc.

http.d - my old standalone http client. Does NOT depend on curl. I'm in the process of replacing it with http2.d, which has a more flexible, asynchronous api (still dependency free, though I have to add OpenSSL and SChannel support for SSL soon). http2 provides an object that kinda works like a browser -it can understand relative links, maintain cookies, etc.

joystick.d - code for accessing XBox 360 controllers (and similar ones, like the PS1 controller via usb) on Windows and Linux.

jsvar.d - a var type similar to Javascript, usable in D. Can be used to read and write JSON with a natural syntax and other dynamic type tasks.

mangle.d - mangles a D name

minigui.d - small, dependency-free (except for simpledisplay.d and color.d but doesn't even need Phobos) widget set, using Win32 native widgets where possible, custom Xlib based ones otherwise. Still work in progress but already works for some basic forms.

oauth.d - OAuth library for client and server. I've used it with Twitter, Linked In, AWeber, Facebook, and more. Has specific functions for the Facebook Graph API, tweeting, serving oauth 1.0 requests, and doing the OAuth authorization flow. Depends on the mhash C library.

querygenerator.d - a user-contributed module for sql query generation

rpc.d - a remote procedure call library for D, making interfaces available across the network. You might prefer the apache thrift bindings or something, this is a custom job that I haven't seriously used.

script.d - a script interpeter based on jsvar.d. The script language is like a cross of D and Javascript. Made for API convenience - very very easy to embed in an application.

sha.d - implementation of SHA1 and SHA2 in pure D (well and some inline asm).

simpleaudio.d - access to WinMM on Windows and ALSA on Linux for waveform sound I/O and MIDI I/O.

simpledisplay.d - dependency-free base windowing library. Allows drawing, input, and other basic functionality. Also allows OpenGL access.

sslsocket.d - Uses OpenSSL to inherit from std.socket.Socket and give client SSL support.

stb_truetype.d - port of C library for writing ttf fonts to images. Has some convenience functions (but they aren't great, works, but not great)

terminal.d - I/O support for the text console. Does real time input, cellular output, getting lines with user editing, coloring, mouse input, and more.

xwindows.d - functions for working with X, beyond what simpledisplay.d offers. Stuff like interacting with the window manager, getting window icons, etc. I wrote it to support my D xlib taskbar.

web.d - wraps a D class in an HTTP api, with automatic url routing, view generation, argument conversion, and much more. Also includes a HTML templating system among other stuff that brings a lot of these modules together.



There's a few other hidden gems in the files themselves, and so much more on my pipeline. Among the ones you might see added in the next month:

game.d - helper functions for writing games (bringing together the display, audio, and joystick stuff). I have OpenGL texture stuff written now, almost done with the high level input api, and some math stuff that will probably be in there.

model.d - loading and displaying a 3d model format with open gl.

midi.d, wav.d - loading, saving, and working with midi and wav files


(Yes, I'm writing a pair of D games again, finally! First time in a long time, but it is moving along well... and I don't need SDL this time!)
January 15, 2015
On Thursday, 15 January 2015 at 15:38:05 UTC, Adam D. Ruppe wrote:

>  mssql.d  - drivers for database.d (wrapping C libraries)

> minigui.d - small, dependency-free (except for simpledisplay.d and color.d but doesn't even need Phobos) widget set, using Win32 native widgets where possible, custom Xlib based ones otherwise. Still work in progress but already works for some basic forms.

Can you let the mssql.d work ok on your minigui.d with ANSI (wstring)?
Insert wstring? Get the SqlException?

Thank you.