Avoiding primitive obsession in .NET
-
all dark, no moon ... good ... hunting.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
-
BillWoodruff wrote:
all dark, no moon ... good ... hunting.
A religious icon wrote:
I am the Light of the world; he who follows Me will not walk in the darkness, but will have the Light of life.
specific quotes from your-brand-of-scripture is inappropriate on every CodeProject forum for very good reasons. message reported as inappropriate.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
-
specific quotes from your-brand-of-scripture is inappropriate on every CodeProject forum for very good reasons. message reported as inappropriate.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
Sweet, Should we report [your comments](https://www.codeproject.com/Insider.aspx?fid=1658735&df=90&mpp=50&sort=Position&spc=Relaxed&select=5917537&tid=5915963) about Sanskrit and the Vedic scripture Bill? Edit: I'm just pointing out something I find hypocritical, if you check your post history you proclaimed your religion ages ago.
-
Wrapping every primitive value in a
class
like that is going to dramatically increase the memory usage of the application, and potentially decrease the performance. After all, there's a reason Java has stack-allocated duplicates of certain heap-allocated classes. The author should really be using astruct
for the wrappers - and preferably arecord struct
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Sweet, Should we report [your comments](https://www.codeproject.com/Insider.aspx?fid=1658735&df=90&mpp=50&sort=Position&spc=Relaxed&select=5917537&tid=5915963) about Sanskrit and the Vedic scripture Bill? Edit: I'm just pointing out something I find hypocritical, if you check your post history you proclaimed your religion ages ago.
You can report anything you want; anything you feel violates CodeProject's ethos. There is a big difference between my comments on the history and linguistics of the Vedas and Sanskrit, on the Mahabharata as drama and metaphysical allegory, and a direct quote from a scripture used as a talking point. I very carefully avoided anything that showed disrespect for Hinduism the same way as I would carefully avoid showing disrespect for Christianity, Islam, etc. The quote (in Urdu) I used from Kabir is poetry. Glad to hear you read my posts !
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
-
-
You can report anything you want; anything you feel violates CodeProject's ethos. There is a big difference between my comments on the history and linguistics of the Vedas and Sanskrit, on the Mahabharata as drama and metaphysical allegory, and a direct quote from a scripture used as a talking point. I very carefully avoided anything that showed disrespect for Hinduism the same way as I would carefully avoid showing disrespect for Christianity, Islam, etc. The quote (in Urdu) I used from Kabir is poetry. Glad to hear you read my posts !
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
Bill, It's probably just poetry. My way of expressing myself in Walcott-esque style. [THE LIGHT OF THE WORLD - Derek Walcott - Saint Lucia - Poetry International](https://www.poetryinternational.com/en/poets-poems/poems/poem/103-28371\_THE-LIGHT-OF-THE-WORLD) Read it to see if you can find that deeper meaning. Might have to read it three or four times. :thumbsup:
-
Yeah, it's called semantic types, and I wrote about this[^] in 2018. :rolleyes:
Latest Article:
Create a Digital Ocean Droplet for .NET Core Web API with a real SSL Certificate on a Domain -
I thought the author’s “fixed” code was awful. Why leave email as a string? Boolean is the worst primitive for this, why did the author leave a boolean? I am trying to get a law passed that all booleans should be converted enums. If I see a class named ClubMember, I would never expect to call ClubMember.isMember(), ever. Maybe ClubMember.getMembershipStatus(). Oof!
-
Wrapping every primitive value in a
class
like that is going to dramatically increase the memory usage of the application, and potentially decrease the performance. After all, there's a reason Java has stack-allocated duplicates of certain heap-allocated classes. The author should really be using astruct
for the wrappers - and preferably arecord struct
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
In a similar vein, the
ClubMember
type in particular made me wish (again) that C# supported enum types with methods."If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
In a similar vein, the
ClubMember
type in particular made me wish (again) that C# supported enum types with methods."If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
Extension methods will get you close to that:
public enum ClubMember
{
NonMember,
Member,
}public static class ClubMemberExtensions
{
public static decimal CalculateAmount(this ClubMember member, decimal productValue) => member switch
{
ClubMember.Member => productValue - 10,
_ => productValue,
};
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I thought the author’s “fixed” code was awful. Why leave email as a string? Boolean is the worst primitive for this, why did the author leave a boolean? I am trying to get a law passed that all booleans should be converted enums. If I see a class named ClubMember, I would never expect to call ClubMember.isMember(), ever. Maybe ClubMember.getMembershipStatus(). Oof!
englebart wrote:
I am trying to get a law passed that all booleans should be converted enums.
That's easy:
public enum Bool
{
True,
False,
FileNotFound,
}What Is Truth? - The Daily WTF[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
englebart wrote:
I am trying to get a law passed that all booleans should be converted enums.
That's easy:
public enum Bool
{
True,
False,
FileNotFound,
}What Is Truth? - The Daily WTF[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer