July 08, 2020
On Wednesday, 8 July 2020 at 03:53:55 UTC, Jordan Wilson wrote:
> Here's something I just did now that might be more relevant:
> echo 'import std; void main() { "bets.json".readText.parseJSON.toPrettyString.writeln; }' | dmd -run - | more
>
> I did this without looking up anything. Whereas before this echo/import std; into dmd -run trick, I would have opened up vim, and hoped that my previous command to pretty print was still in the history! (using python if I remember correctly).

>
> Jordan

Have a look at jq [1] and jqed. What's up with the bets? Writing a betfair bot by any chance?

[1] https://stedolan.github.io/jq/
July 08, 2020
On Friday, 26 June 2020 at 09:10:57 UTC, Mike Parker wrote:
> On Friday, 26 June 2020 at 05:39:59 UTC, H. S. Teoh wrote:
>
>>
>> Maybe we should have a Most Useful One-Line D Program contest. :-P
>>
>
> Or a blog post showing off all of this and explaining the compiler flags :-)

That would be great if someone could do this! I would like to learn and show off the D one-liners in the company.
July 08, 2020
On Wednesday, 24 June 2020 at 21:37:37 UTC, H. S. Teoh wrote:
> Phobos sometimes gets a bad name around these parts, but actually it's pretty cool (in spite of well-known warts).  One of the cool things about it is the batteries-included philosophy that used to be its guiding principle.  Over the course of my usage of D, the following have stood out as being particularly convenient when I needed it:
>
> 1) std.bigint: one time, I was working on a quadratic irrational arithmetic module, and pretty quickly discovered that numerical overflow was a problem that cropped up pretty often.  Or rather, I was seeing what I *thought* was caused by arithmetic overflow, and wanted to be sure.  Solution?  Easy: templatize the coefficient type, import std.bigint, and within several minutes, I have a working implementation that can support arbitrarily large coefficients -- with which I not only confirmed that the observed problems were caused by arithmetic overflow, but also obtained a working solution simultaneously.  Win!
>
> 2) std.numeric.poly: another time, I had to work with evaluating a bunch of polynomials, and specifically, with evaluating their roots quickly and accurately.  I could roll my own, poorly, and get results that may or may not be highly-skewed by accumulated errors... or I could use std.numeric.poly to get a reliable evaluation of the polynomial, and, better yet, use std.numeric.findRoot to compute roots with the confidence that the value I get will have as small an error as is possible within the constraints of built-in hardware floats. Plus, this saved me tons of development and debugging time to roll my own solution. Win!
>
> 3) Just today, I needed to implement a fast Fourier transform. Not expecting this to be in Phobos, I was glancing over various algorithms to decide which one suited my use case best and is easy enough to implement quickly. And then I discovered std.numeric.Fft, already done and nicely-packaged and ready to use.  Total win!!
>
> Seriously, D + Phobos is cool beans.  Yes it's not perfect -- the language has its fair share of dark corners, WATs, and Phobos has its share of poorly-designed APIs and outdated modules.  But seriously, a lot of what's currently there is pretty darned cool, and we shouldn't let all the bad stuff cloud our appreciation of just how cool it already is.
>
>
> T

I was honestly surprised to read here that Phobos gets a bad name. But I am not a D expert to judge anyway.

For example, I simply can't stand Python stdlib docs and only go there when everything else fails.
They are really hard to read for me for some unknown reason (design, wording or both?) and I know that I am not alone in this. But Python can get away with it, right and why's that? :)
On the contrary Scala standard library is a great example of being well written and designed.

Personally, I was impressed by Phobos once I started going through the docs for the first time after reading Ali's "Programming in D" book. It is actually Phobos that made me believe that D has a solid and rich standard library. I was pleasantly surprised that description of many functions contained complexity information and pragmatically explained how things work.
For example, std.algorithm contains many cool things like "balancedParens" or "levenshteinDistance" (which even Python doesn't have and needs an external C++ lib to use). I like how each module is split into logical groups and how the function names are simply linguistically more precise. If there is no a function that you expect to have, you get a feeling that it is not there because it is probably a one liner in D or something that should be done with the available tools. I also like the general design and layout. It is all very readable. All that persuaded me to proceed with the language further. My only critique or rather a wish would be more code examples.
Of course, I can imagine things are not all pretty for people working with D for many years and it is absolutely fine. It should be like this because there will be no challenge and therefore progress. However, from beginners view Phobos is cool.


July 08, 2020
Maybe we should add an option to rdmd that compile and run a string, importing std automatically? Writing one-liners would be as easy as
rdmd -dscript 'writeln("hello, shell");'
July 08, 2020
On Wednesday, 8 July 2020 at 10:15:17 UTC, Ogi wrote:
> Maybe we should add an option to rdmd that compile and run a string, importing std automatically? Writing one-liners would be as easy as
> rdmd -dscript 'writeln("hello, shell");'

rdmd --eval 'writeln("hello, shell");'

```
  --eval=code        evaluate code as in perl -e (multiple --eval allowed)
  --loop             assume "foreach (line; stdin.byLine()) { ... }" for eval
```
July 08, 2020
On Wednesday, 8 July 2020 at 10:15:17 UTC, Ogi wrote:
> Maybe we should add an option to rdmd that compile and run a string, importing std automatically? Writing one-liners would be as easy as
> rdmd -dscript 'writeln("hello, shell");'

Try rdmd --eval='writeln("hello, shell");'
July 08, 2020
On Wednesday, 8 July 2020 at 10:34:55 UTC, Dennis wrote:
> On Wednesday, 8 July 2020 at 10:15:17 UTC, Ogi wrote:
>> Maybe we should add an option to rdmd that compile and run a string, importing std automatically? Writing one-liners would be as easy as
>> rdmd -dscript 'writeln("hello, shell");'
>
> rdmd --eval 'writeln("hello, shell");'
>
> ```
>   --eval=code        evaluate code as in perl -e (multiple --eval allowed)
>   --loop             assume "foreach (line; stdin.byLine()) { ... }" for eval
> ```

Whoa! rdmd is cool, too.
July 08, 2020
On Wednesday, 8 July 2020 at 07:39:03 UTC, Panke wrote:
> On Wednesday, 8 July 2020 at 03:53:55 UTC, Jordan Wilson wrote:
>> Here's something I just did now that might be more relevant:
>> echo 'import std; void main() { "bets.json".readText.parseJSON.toPrettyString.writeln; }' | dmd -run - | more
>>
>> I did this without looking up anything. Whereas before this echo/import std; into dmd -run trick, I would have opened up vim, and hoped that my previous command to pretty print was still in the history! (using python if I remember correctly).
>
>>
>> Jordan
>
> Have a look at jq [1] and jqed.

After writing the post, I recalled that several months ago I actually did install jq for that very issue of just quickly inspecting a json file, but clearly forgot all about it. I suppose it illustrates my general point...a familiar sledgehammer might be more useful than an unfamiliar hammer.

> What's up with the bets?

Haha, not a bot, but rather data gathering of NBA odds (before everything was shut down).

Jordan
July 09, 2020
On Tuesday, 7 July 2020 at 22:29:36 UTC, H. S. Teoh wrote:
> [...]
>
> Awesome stuff!!  We should collect a library of these one-liners, maybe on the wiki or something, that can serve as a useful reference.  It can also be used to show off D's capabilities too.
>
>
> T

dmd -run code.d | dmd -
July 09, 2020
On Thursday, 9 July 2020 at 15:31:32 UTC, Petar Kirov [ZombineDev] wrote:
> On Tuesday, 7 July 2020 at 22:29:36 UTC, H. S. Teoh wrote:
>> [...]
>>
>> Awesome stuff!!  We should collect a library of these one-liners, maybe on the wiki or something, that can serve as a useful reference.  It can also be used to show off D's capabilities too.
>>
>>
>> T
>
> dmd -run code.d | dmd -

So that compiles and runs code.d and then passes the result to dmd to build?