January 27, 2022

On Wednesday, 26 January 2022 at 16:04:36 UTC, Steven Schveighoffer wrote:

>

A property is a functional setter/getter (or only one of those) that prevents incorrect usage.

For example, if you have a global int, and it really should only be in the range of 1 to 1000, you can guard the setting of the int to make sure that value was correct.

Or if you have a class reference stored globally, you may want to prevent someone from reassigning the class reference to another object. Then you can restrict access to getting only, and not allow setting.

You can implement a property in D at global level, e.g.:

private Resource _resource;

public Resource resource() { return _resource; } // only can access via this property

-Steve

Oh so it was a class property like I thought! Thanks for the explanation!

January 27, 2022

On Wednesday, 26 January 2022 at 23:13:56 UTC, MrJay wrote:

>

a lot of code practices people recommend such as not using macros is because of team environments' because many convenient code practices can easily cause confusion for your peers. but I still dont understand why people see it as a sin of coding to use global variables, it depends on the code base and the project.

Yeah, I thought the same hence why I made this question. Tho from what I've seen, most of people (at least in the D community) use whatever does the job best so global variables can be useful IF used with caution. But I realized that in my case, wrapping my variables in a struct is a better choice cause not only it's more convenient but I will also have a problem when I implement mult-therading support!

>

In some of my code there is only global variables because one of the languages I use only uses global variables so if something is broken it takes a hot minute, I dont know what function is causing the error, just have to go through them all.

Yeah, that's very very bad indeed!

Thanks a lot for your time! Really appreciate it!

January 27, 2022

On Wednesday, 26 January 2022 at 23:40:48 UTC, H. S. Teoh wrote:

>

"WHAT I was thinking when I wrote this?!"

Yep! That's totally me every single time! When I'm writing the code I feel like a genius! But I only understand how much of an idiot I am after I read the same code some months later. We learn and improve I guess...

>

"WHAT was I trying to do when I wrote this

Totally me again! Tbh, How many times have you though about solving a problem and then down the road, you thought of a better way to do it that is both more performant and more continent and thought "why did I wrote this code this way? It's completely stupid!"? Yet at the time you wrote the code, it looked perfect! Humans are interesting creatures...

January 27, 2022

On Thursday, 27 January 2022 at 00:45:20 UTC, forkit wrote:

>

Without globals, I'd never have bothered ;-)

This may sound stupid but you would never have bothered what? Doing the project?

1 2 3 4 5 6 7
Next ›   Last »