Re: why std.stdio.File is a struct?

2016-10-23 Thread Namespace via Digitalmars-d
On Sunday, 23 October 2016 at 06:36:21 UTC, Jonathan M Davis wrote: You can mark a parameter as ref, and you get something similar to C++'s &, except that it only works on parameters, return types, and the variable for the current element in a foreach loop (you can't declare local variables

Re: why std.stdio.File is a struct?

2016-10-23 Thread Jonathan M Davis via Digitalmars-d
On Sunday, October 23, 2016 06:13:29 lumpyzhu via Digitalmars-d wrote: > thanks.. > but structs are copy by value, > In C++, I can use reference to avoid value-copy, > > -- > class MyClass {}; > void myFunc(const MyClass& a, MyClass& b) {...}; > > { >

Re: why std.stdio.File is a struct?

2016-10-23 Thread lumpyzhu via Digitalmars-d
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis wrote: On Thursday, October 20, 2016 06:59:12 lumpyzhu via Digitalmars-d wrote: std.stdio.File has reference counter inside, why not std.stdio.File is class? By using a struct with a reference count, you get deterministic

Re: why std.stdio.File is a struct?

2016-10-21 Thread Chris via Digitalmars-d
On Thursday, 20 October 2016 at 12:24:14 UTC, ketmar wrote: On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis wrote: In general, in D, if you don't need inheritance and polymorphism, you probably shouldn't be using a class. and even if you need, most of the time it is better to

Re: why std.stdio.File is a struct?

2016-10-20 Thread ketmar via Digitalmars-d
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis wrote: In general, in D, if you don't need inheritance and polymorphism, you probably shouldn't be using a class. and even if you need, most of the time it is better to write templated free functions with constraints instead. ;-)

Re: why std.stdio.File is a struct?

2016-10-20 Thread Kagamin via Digitalmars-d
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis wrote: User-defined types that manage system resources are pretty much always better off as structs so that they can have deterministic destruction. They could be reference counted classes if it played well with the language.

Re: why std.stdio.File is a struct?

2016-10-20 Thread Jonathan M Davis via Digitalmars-d
On Thursday, October 20, 2016 06:59:12 lumpyzhu via Digitalmars-d wrote: > std.stdio.File has reference counter inside, > why not std.stdio.File is class? By using a struct with a reference count, you get deterministic destruction, and the file will be closed as soon as the reference count hits

why std.stdio.File is a struct?

2016-10-20 Thread lumpyzhu via Digitalmars-d
std.stdio.File has reference counter inside, why not std.stdio.File is class?