www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Article: Why I use the D programming language for scripting

reply aberba <karabutaworld gmail.com> writes:
It's finally out!

https://opensource.com/article/21/1/d-scripting
Jan 31
next sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 1/31/21 3:36 PM, aberba wrote:
 It's finally out!
 
 https://opensource.com/article/21/1/d-scripting
Hm... right off I see the shebang is not the first line in the example. It has to be. Nice writeup! -Steve
Jan 31
parent reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Sunday, 31 January 2021 at 20:47:13 UTC, Steven Schveighoffer 
wrote:
 On 1/31/21 3:36 PM, aberba wrote:
 It's finally out!
 
 https://opensource.com/article/21/1/d-scripting
Hm... right off I see the shebang is not the first line in the example. It has to be.
Please fix, Aberba, right now the examples don't work because of this... -- Bastiaan.
Feb 01
parent reply aberba <karabutaworld gmail.com> writes:
On Monday, 1 February 2021 at 11:29:02 UTC, Bastiaan Veelo wrote:
 On Sunday, 31 January 2021 at 20:47:13 UTC, Steven 
 Schveighoffer wrote:
 On 1/31/21 3:36 PM, aberba wrote:
 It's finally out!
 
 https://opensource.com/article/21/1/d-scripting
Hm... right off I see the shebang is not the first line in the example. It has to be.
Please fix, Aberba, right now the examples don't work because of this... -- Bastiaan.
Yes, noted. I don't have direct access to edit it myself. I have to wait till the editors make the changes (depending on their TZ) I should really get someone here to proofread it next time 😅 Sorry about that.
Feb 01
parent reply Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Monday, 1 February 2021 at 11:52:18 UTC, aberba wrote:
 On Monday, 1 February 2021 at 11:29:02 UTC, Bastiaan Veelo 
 wrote:
 On Sunday, 31 January 2021 at 20:47:13 UTC, Steven 
 Schveighoffer wrote:
 On 1/31/21 3:36 PM, aberba wrote:
 It's finally out!
 
 https://opensource.com/article/21/1/d-scripting
Hm... right off I see the shebang is not the first line in the example. It has to be.
Please fix, Aberba, right now the examples don't work because of this... -- Bastiaan.
Yes, noted. I don't have direct access to edit it myself. I have to wait till the editors make the changes (depending on their TZ) I should really get someone here to proofread it next time 😅 Sorry about that.
Perhaps we can create a channel on the dlang Slack for proofreading articles and blog posts, so that more people can have a chance to review an article before publishing.
Feb 01
parent reply drug <drug2004 bk.ru> writes:
On 2/1/21 3:14 PM, Petar Kirov [ZombineDev] wrote:
 On Monday, 1 February 2021 at 11:52:18 UTC, aberba wrote:
 On Monday, 1 February 2021 at 11:29:02 UTC, Bastiaan Veelo wrote:
 On Sunday, 31 January 2021 at 20:47:13 UTC, Steven Schveighoffer wrote:
 On 1/31/21 3:36 PM, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
Hm... right off I see the shebang is not the first line in the example. It has to be.
Please fix, Aberba, right now the examples don't work because of this... -- Bastiaan.
Yes, noted. I don't have direct access to edit it myself. I have to wait till the editors make the changes (depending on their TZ) I should really get someone here to proofread it next time 😅 Sorry about that.
Perhaps we can create a channel on the dlang Slack for proofreading articles and blog posts, so that more people can have a chance to review an article before publishing.
That's a really good idea!
Feb 01
parent reply Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Monday, 1 February 2021 at 12:26:02 UTC, drug wrote:
 On 2/1/21 3:14 PM, Petar Kirov [ZombineDev] wrote:
 [..]

 Perhaps we can create a channel on the dlang Slack for 
 proofreading articles and blog posts, so that more people can 
 have a chance to review an article before publishing.
That's a really good idea!
join!
Feb 01
parent reply drug <drug2004 bk.ru> writes:
On 2/1/21 3:28 PM, Petar Kirov [ZombineDev] wrote:
 

How can I join? I used slack once for a short period some time ago.
Feb 01
parent reply Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Monday, 1 February 2021 at 12:49:28 UTC, drug wrote:
 On 2/1/21 3:28 PM, Petar Kirov [ZombineDev] wrote:
 

 join!
How can I join? I used slack once for a short period some time ago.
Any dlang slack member can invite new members by their email (I think even temporary email addresses are fine). On which email shall I send you an invite?
Feb 01
next sibling parent drug <drug2004 bk.ru> writes:
On 2/1/21 4:37 PM, Petar Kirov [ZombineDev] wrote:
 On Monday, 1 February 2021 at 12:49:28 UTC, drug wrote:
 On 2/1/21 3:28 PM, Petar Kirov [ZombineDev] wrote:

How can I join? I used slack once for a short period some time ago.
Any dlang slack member can invite new members by their email (I think even temporary email addresses are fine). On which email shall I send you an invite?
sent directly
Feb 01
prev sibling parent reply sighoya <sighoya gmail.com> writes:
On Monday, 1 February 2021 at 13:37:38 UTC, Petar Kirov 
[ZombineDev] wrote:
 Any dlang slack member can invite new members by their email (I 
 think even temporary email addresses are fine). On which email 
 shall I send you an invite?
Is there any PM mechanism on board, no?
Feb 01
parent reply Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Monday, 1 February 2021 at 18:11:43 UTC, sighoya wrote:
 On Monday, 1 February 2021 at 13:37:38 UTC, Petar Kirov 
 [ZombineDev] wrote:
 Any dlang slack member can invite new members by their email 
 (I think even temporary email addresses are fine). On which 
 email shall I send you an invite?
Is there any PM mechanism on board, no?
You mean does Slack have private messages? Yes it does.
Feb 01
parent sighoya <sighoya gmail.com> writes:
On Tuesday, 2 February 2021 at 07:28:36 UTC, Petar Kirov 
[ZombineDev] wrote:
 On Monday, 1 February 2021 at 18:11:43 UTC, sighoya wrote:
 Is there any PM mechanism on board, no?
You mean does Slack have private messages? Yes it does.
No I meant, if this board has such options, don't like to paste email data in their. Anyway, could you invite me over the following mail: <my forum username> gmail.com That would be nice. I'm interested in chat discussions.
Feb 02
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/31/2021 12:36 PM, aberba wrote:
 It's finally out!
 
 https://opensource.com/article/21/1/d-scripting
Very nice and informative article!
Jan 31
prev sibling next sibling parent Jon Degenhardt <jond noreply.com> writes:
On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
Very nice! Clearly I'm not taking enough advantage of scripting capabilities! --Jon
Jan 31
prev sibling next sibling parent sighoya <sighoya gmail.com> writes:
On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
Thanks for your work, nice article, I wasn't even aware how easy this is.
Jan 31
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
FYI, the code will compile faster if you use `dmd -run` instead of `rdmd`. If you have multiple files that need to be compiled you can use `dmd -i -run`. -- /Jacob Carlborg
Feb 01
parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 1 February 2021 at 09:36:15 UTC, Jacob Carlborg wrote:
 On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
FYI, the code will compile faster if you use `dmd -run` instead of `rdmd`. If you have multiple files that need to be compiled you can use `dmd -i -run`. -- /Jacob Carlborg
Unfortunately, you can't pass more than one command-line argument
Feb 01
parent reply Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Monday, 1 February 2021 at 11:10:28 UTC, Paul Backus wrote:
 On Monday, 1 February 2021 at 09:36:15 UTC, Jacob Carlborg 
 wrote:
 On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
FYI, the code will compile faster if you use `dmd -run` instead of `rdmd`. If you have multiple files that need to be compiled you can use `dmd -i -run`. -- /Jacob Carlborg
Unfortunately, you can't pass more than one command-line
It is possible, using `/usr/bin/env -S command arg1 arg2` , as of coreutils 8.30. I have been using it at work and it's working perfectly. This functionality was already supported by FreeBSD [1] for ~15 years, but the coreutils developers implemented it just ~3 years ago [2]. The main disadvantage is that it's obviously not very portable, e.g. all users/developers need to use a modern linux distro, but for some teams this requirement already there for other reasons, so it's not a problem. Example: https://gist.github.com/PetarKirov/72168d8dc909c670444ca649ec28f80f This was extracted from a larger project, so it may not be useful on its own, but hopefully it should be enough to showcase the usage. Also, if you can use rund [3], it's likely a much cleaner option. [1]: https://www.freebsd.org/cgi/man.cgi?env [2]: https://lists.gnu.org/r/coreutils/2017-05/msg00020.html [3]: https://github.com/dragon-lang/rund
Feb 01
parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 1 February 2021 at 12:11:46 UTC, Petar Kirov 
[ZombineDev] wrote:
 On Monday, 1 February 2021 at 11:10:28 UTC, Paul Backus wrote:
 Unfortunately, you can't pass more than one command-line 

It is possible, using `/usr/bin/env -S command arg1 arg2` , as of coreutils 8.30. I have been using it at work and it's working perfectly. This functionality was already supported by FreeBSD [1] for ~15 years, but the coreutils developers implemented it just ~3 years ago [2].
This is great, thanks! I just checked, and it's available in Debian stable, so most distros should have it by now.
Feb 01
parent Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Monday, 1 February 2021 at 12:41:19 UTC, Paul Backus wrote:
 On Monday, 1 February 2021 at 12:11:46 UTC, Petar Kirov 
 [ZombineDev] wrote:
 On Monday, 1 February 2021 at 11:10:28 UTC, Paul Backus wrote:
 Unfortunately, you can't pass more than one command-line 

It is possible, using `/usr/bin/env -S command arg1 arg2` , as of coreutils 8.30. I have been using it at work and it's working perfectly. This functionality was already supported by FreeBSD [1] for ~15 years, but the coreutils developers implemented it just ~3 years ago [2].
This is great, thanks!
I was missing this feature often, I'm glad I found it recently ;)
 I just checked, and it's available in Debian stable, so most 
 distros should have it by now.
Yes, I think it's safe to use on Linux nowadays. In the worst case a user may need to upgrade their coreutils. I just mention this because a teammate was still on Ubuntu 16.04 or 18.04 so he had to upgrade [1]. [1]: https://packages.ubuntu.com/search?keywords=coreutils&searchon=names&suite=all§ion=all
Feb 01
prev sibling next sibling parent Marcone <marcone email.com> writes:
On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
D lang is life! I used Python for scripting, but D lang is better, I don't need install interpreter for execute it. I hope someay fobos have same support as Python library.
Feb 01
prev sibling parent reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
If the article is about scripting, then the article will contain examples of scripts used in business. For example, to delete all dub caches in a directory: Version via Windows .bat: echo off FOR /D %%f IN ( .\* ) DO ( IF EXIST .\%%f\.dub ( echo .\%%f\.dub rmdir /q /s .\%%f\.dub ) ) Version via Dlang: module dubcache; import std.file; import std.path; import std.stdio; void main( string[] args ) { foreach( dir; dirEntries( args[0].dirName, SpanMode.shallow ) ) { if ( dir.baseName == ".dub" ) { writeln( "REMOVED: ", dir ); rmdirRecurse( dir.name ); } } } or module dubcache; import std; void main( string[] args ) { dirEntries( args[0].dirName, SpanMode.shallow ) .filter!( a => a.baseName == ".dub" ) .each!( ( a ) { writeln( a ); rmdirRecurse( a ); } ); }
Feb 01
next sibling parent reply =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Tuesday, 2 February 2021 at 03:53:43 UTC, Виталий Фадеев wrote:
 On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
If the article is about scripting, then the article will contain examples of scripts used in business. For example, to delete all dub caches in a directory:
Remove dub cache in subsirectories: module dubcache; // Reason: // each cache take 50 - 200 MB of disk space // Goal: // scan dirs and remove caches // // ./ // a/ // b/ // .dub/ <- target // c/ import std; void main( string[] args ) { dirEntries( args[0].dirName, SpanMode.shallow ) .filter!( a => a.isDir ) .map!( a => buildPath( a.name, ".dub" ) ) .filter!( a => a.exists ) .each!( ( a ) { writeln( a ); rmdirRecurse( a ); } ); } Source: https://run.dlang.io/is/ah1Vtp And we see what it not simple as windows .bat
Feb 01
parent =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Tuesday, 2 February 2021 at 04:24:48 UTC, Виталий Фадеев wrote:
 On Tuesday, 2 February 2021 at 03:53:43 UTC, Виталий Фадеев 
 wrote:
 On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 It's finally out!

 https://opensource.com/article/21/1/d-scripting
If the article is about scripting, then the article will contain examples of scripts used in business.
And we see what it not simple as windows .bat
Perhaps the best version would be a high-level add-on over rdmd with Dlang syntax. . "main()" and "import std" will be hidden. For example, the final result will look like this: dirEntries( args[0].dirName, SpanMode.shallow ) .filter!( a => a.isDir ) .map!( a => buildPath( a.name, ".dub" ) ) .filter!( a => a.exists ) .each!( ( a ) { writeln( a ); rmdirRecurse( a ); } ); and the file will have the extension ".ds"
Feb 01
prev sibling parent aberba <karabutaworld gmail.com> writes:
On Tuesday, 2 February 2021 at 03:53:43 UTC, Виталий Фадеев wrote:
 On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
 [...]
If the article is about scripting, then the article will contain examples of scripts used in business. [...]
Nice examples!
Feb 02