www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Looking for some thoughtful review of my first D program

reply Thomas Teixeira <thomas.teixeira+dforum startmail.com> writes:
Hi, you all !

I've wanted to look at D for the last two years, being a C fanboy 
and not fond of C++.
It seemed like a good alternative between some delightful extra 
new stuff and keeping C-like experience : performances and code 
style wise.

I wrote my first CLI program this weekend and would like some 
code review, if some of you don't mind. :)
The source code can be found here : 
https://git.sr.ht/~nasmevka/tmp/tree/main/item/tmp.d

I apologize for the way my code looks like. I do not use LSPs and 
having function definition's name on their own line make `grep 
^funcname` really powerful.

Templates are really powerful, and I feel like I do not use them 
near enough ? 🤷


Open to all form of criticism ☺️
Dec 27 2023
parent Renato <renato athaydes.com> writes:
On Wednesday, 27 December 2023 at 11:08:26 UTC, Thomas Teixeira 
wrote:
 Hi, you all !

 I've wanted to look at D for the last two years, being a C 
 fanboy and not fond of C++.
 It seemed like a good alternative between some delightful extra 
 new stuff and keeping C-like experience : performances and code 
 style wise.

 I wrote my first CLI program this weekend and would like some 
 code review, if some of you don't mind. :)
 The source code can be found here : 
 https://git.sr.ht/~nasmevka/tmp/tree/main/item/tmp.d

 I apologize for the way my code looks like. I do not use LSPs 
 and having function definition's name on their own line make 
 `grep ^funcname` really powerful.

 Templates are really powerful, and I feel like I do not use 
 them near enough ? 🤷


 Open to all form of criticism ☺️
Your code seems pretty good to me :) Just one minor comment: ```d File file = File(filename, "w"); scope(exit) file.close; ``` You don't need to close the file because that's done automatically as the `file` goes out of scope (as explained [in the docs](https://dlang.org/library/std/stdio/file.html)). I believe it uses [RefCounted](https://dlang.org/library/std/typecons/safe_ref_counted.html) to do that.
Dec 30 2023