Why people dislike global variables so much while I find them so convenient?

rempas rempas at tutanota.com
Thu Jan 27 08:09:28 UTC 2022


On Wednesday, 26 January 2022 at 15:36:52 UTC, H. S. Teoh wrote:
> Thanks to UFCS, you don't need to define every function that 
> operates on the struct/class as a method. Free functions work 
> just fine.
>
> I.e., instead of this:
>
> 	struct MyData {
> 		int x;
> 		void method() {
> 			x++;
> 		}
> 	}
>
> 	MyData data;
> 	data.method();
>
> you could also write this:
>
> 	struct MyData {
> 		int x;
> 	}
>
> 	void method(ref MyData mydata) {
> 		mydata.x++;
> 	}
>
> 	MyData data;
> 	data.method();
>
>
> T

That's cool! Thanks!


More information about the Digitalmars-d mailing list