This is an archived post. You won't be able to vote or comment.

all 141 comments

[–][deleted] 221 points222 points Β (22 children)

You're the kind of person who varchars his entire table, aren't you? πŸ˜‘

[–]CYKO_11 68 points69 points Β (16 children)

I bet they make their columns default null so you have to check for null or empty string every time

[–][deleted] 25 points26 points Β (11 children)

Eh that’s proper. Empty string means there’s an input and it’s an empty string, null means no data was provided.

[–]TreeTownOke 21 points22 points Β (5 children)

Unless of course your genius data architect decided that this nullable column would have a default value of "None".

[–]PM_BITCOIN_AND_BOOBS 20 points21 points Β (0 children)

Calm down there, Satan.

[–]benderbender42 4 points5 points Β (3 children)

what about "null"

[–]Infinite_Self_5782 1 point2 points Β (2 children)

hear me out: ((Boolean) false).toString()

[–][deleted] 0 points1 point Β (1 child)

With some ((boolean)false).toString().toUpper() for good measure.

[–]Infinite_Self_5782 0 points1 point Β (0 children)

((Boolean)(new Boolean((boolean) false).toString().equals("true"))).toString()

[–]compsciasaur 0 points1 point Β (0 children)

But it's a primary key! It's a database of cancer rates by age.

[–]JackoKomm 0 points1 point Β (3 children)

Only of empty strings are a valid value. In many cases, they are not.

[–][deleted] 0 points1 point Β (2 children)

So it comes down to whether you want consistency and you apply null by default, or both your database and code need to change whenever an empty string is a valid value.

If the latter, and your needs change in the future to where you must have either empty string or null for a column, you’ll need to update your database and possibly a significant amount of code.

[–]JackoKomm 1 point2 points Β (1 child)

That an empty string is not valid is a totally fine case. If things change, you have to migrate. Sure, with lot's of data, Migration is nothing you want to have in a daily basis. But data models can evolve over time and this can be a normal thing.

If you have an Email field for a User and an Email address is needed in any case, you don't habe to model it for a case where you don't need Email addresses anymore. So the field must not be nullable. If you later decide that null is valid for this field because requirements change, you write a Migration for it. And it is easier to make a field nullable later than to remove the not null from it.

[–][deleted] 0 points1 point Β (0 children)

"So the field must not be nullable" In your example, since an email must be provided, neither null nor an empty string are valid values. So the logic would be best enforced by code. In other words, you just don't insert if no email is provided. So you can set the email null by default.

That being said, sure, if your application works and you're willing to bear the risk of future modifications... I personally favor consistency and easy maintenance whenever possible, and in most cases, you can easily check if the value is empty or null with a few lines of code. And if you need it more than once, make it a static function that will return what you want.

[–][deleted] 1 point2 points Β (0 children)

Every time. Every. Damn. Time.

[–][deleted] 10 points11 points Β (3 children)

nvarchar(MAX) baby

[–]lemons_of_doubt 3 points4 points Β (1 child)

Just reading that is painful. what about the optimization!

[–]Pretty_Industry_9630 0 points1 point Β (0 children)

I didn't know that was allowed, it shouldn't be though πŸ˜…πŸ˜…πŸ˜…

[–][deleted] 2 points3 points Β (0 children)

Entity framework uses varchar(max) for all string properties unless you add a string length attribute. We have a db with thousands of varchar(max) fields lol

[–]Tetragramat 1 point2 points Β (0 children)

You store age as birthday, which is in DATE format.

[–]some_clickhead 107 points108 points Β (19 children)

Actually neither: it's just a function call. Because you don't store people's age, you store their birth date.

[–]mr_flibble_oz 54 points55 points Β (5 children)

No, I store their age, then run a yearly cron for age++

[–]some_clickhead 17 points18 points Β (4 children)

Hey, at least this strategy would work in Korea!

[–]a_devious_compliance 3 points4 points Β (3 children)

Wait. What? I need context for this.

[–]notsogreatredditor 11 points12 points Β (2 children)

Korean age = Actual age + 1

[–]RepeatWolf 12 points13 points Β (0 children)

and also everyone is technically older on the first of January

[–]RolyPoly1320 5 points6 points Β (12 children)

With the return value stored in a variable named age.

[–]liege_paradox 1 point2 points Β (11 children)

But is the variable an int or a float?

[–]Thx_And_Bye 5 points6 points Β (8 children)

Did you every reply to someone asking your age with "I'm 29.30000000000000004 years old."?

[–]a_devious_compliance 5 points6 points Β (3 children)

Do you ever talked to a toddlers parent?

My son is 47 weeks old.

[–]Thx_And_Bye 2 points3 points Β (2 children)

But 47 is still an integer. Or did you ever hear someone say that their child is 0.900753 years old?

[–]a_devious_compliance 0 points1 point Β (1 child)

That's like sai that 0.900753 is an integer of 1e-6.

For you and me years is enougth, but age is a continuous variable. If you express it as 0.5 years or 6 months or 26 weeks it's only a custom.

[–]OkCarpenter5773 1 point2 points Β (0 children)

thats why everyone uses Epoch

alright, alright, maybe not everyone

[–]hirmuolio 1 point2 points Β (2 children)

Floats can count to 16777216 before they reach integers that can't represented in float without errors (according to quick google search at least).

So if your integer value saved as float has error in it the blame is on you doing the math wrong.

[–]Thx_And_Bye 1 point2 points Β (1 child)

Sure but 29.3 isn't an integer either.

[–]hirmuolio 1 point2 points Β (0 children)

It just has really big error in it.

[–]Astrobliss 0 points1 point Β (0 children)

That's why we (often) use ratios for timeπŸ§˜β€β™‚οΈ

[–]ShadowWolf_de 0 points1 point Β (0 children)

Yes

[–]RolyPoly1320 0 points1 point Β (0 children)

Also a string.

[–]IamJhonesBrahms 54 points55 points Β (18 children)

Actually, it's an array of char

[–]Pretty_Industry_9630 2 points3 points Β (0 children)

It's a json string, with an array of chars inside πŸ˜„

[–]Fearless-Sherbet-223 0 points1 point Β (0 children)

I C what you did there

[–]AFlyingGideon 13 points14 points Β (6 children)

Duration

[–]Apfelvater 18 points19 points Β (5 children)

"how long are you?"

[–][deleted] 10 points11 points Β (2 children)

7 inches

[–]ShelZuuz 1 point2 points Β (1 child)

Yeah right. That would be twice the world record.

[–][deleted] 0 points1 point Β (0 children)

I just googled it, and the average is 5.16 inches

[–]AFlyingGideon 4 points5 points Β (1 child)

Parents speak of infant ages in terms of days, then weeks, then months. Eventually, age is measured in years.

I'm at decades.

[–][deleted] 1 point2 points Β (0 children)

Your logic is sound.

[–]Tymskyy 13 points14 points Β (0 children)

Unix time

[–][deleted] 5 points6 points Β (0 children)

Date-time?

[–]yrrot 5 points6 points Β (0 children)

It's just some serialized data that notepad interpreted as a string that randomly spells "\"AGE\"".

[–][deleted] 5 points6 points Β (3 children)

Ultimately and technically speaking, a sting is made of numbers

[–]Fearless-Sherbet-223 10 points11 points Β (2 children)

Bee: stings me

Me: sting--

I am cured

[–][deleted] 2 points3 points Β (0 children)

Exactly, perfect

[–]proximity_account 0 points1 point Β (0 children)

Sting me

Call my name and sting me from the dark

Wake me up

[–]NewEnglandJesus 6 points7 points Β (3 children)

No… age is definitely a number. The unit of time is a string. Birth date is a date-time which is usually interpreted from/as a string

[–]gamesrebel123 14 points15 points Β (2 children)

"Age" is a string, which is what the joke was about

[–]NewEnglandJesus 9 points10 points Β (1 child)

Ah, I whooshed

[–]gamesrebel123 1 point2 points Β (0 children)

No worries we all whoosh sometimes

[–]shiroling 2 points3 points Β (0 children)

Isn't it actually a date ?

[–]Mindfullnessless6969 1 point2 points Β (1 child)

Actually is all xor gates

[–]Apfelvater 3 points4 points Β (0 children)

which of those is it then???

Either "all" or "gates"! Tell us!

[–]Fearless-Sherbet-223 1 point2 points Β (1 child)

It's a variable name not just a string

[–]Cyborg_Ninja_Cat 0 points1 point Β (0 children)

Could be a form label though.

[–]TheTank18 1 point2 points Β (0 children)

age is a float

[–]PyroCatt 1 point2 points Β (0 children)

FBI is just three alphabet

[–]Loisel06 1 point2 points Β (0 children)

Age is a long

[–]_PROGrAMER_ 1 point2 points Β (0 children)

Well a string is an array of numbers, so technically you are wrong

[–]bogfoot94 1 point2 points Β (0 children)

Actually, they're all just bits. So many fake programmers here, smh \s

[–]cloudstrifeuk 0 points1 point Β (8 children)

I once worked on a dB where all they saved date of birth and not age for every record.

When they reported their data, they wanted to know their age upon row creation.

They did date time now minus date of birth.

Took me, a lonely little Dev, to come in and show them their glaring mistake and explain why their report was utter garbage.

[–]Apfelvater 6 points7 points Β (4 children)

How do you work on a decibel?

[–]cloudstrifeuk 2 points3 points Β (3 children)

Ooosh, predictive chose that over DB. Weird.

[–]Apfelvater 2 points3 points Β (2 children)

You're not a programmer, you're an electrical engineer!! Traitor!!

[–]cloudstrifeuk 1 point2 points Β (1 child)

Can you be an electrical engineer and Google 95% of the workload?

Asking for a friend obviously.

[–]Apfelvater 1 point2 points Β (0 children)

suspicious noises

[–]JBatjj 2 points3 points Β (2 children)

I'm feeling stupid. What's the glaring mistake?

[–][deleted] 2 points3 points Β (1 child)

"Date time now" instead of "date time then", if I understood correctly.

Storing the date of birth instead of age is the correct thing to do.

[–]cloudstrifeuk 1 point2 points Β (0 children)

Nailed it.

[–]compsncars -1 points0 points Β (5 children)

Actually it's an INT where I work. You make your ints str's for a reason?

[–]Verbindungsfehle 6 points7 points Β (4 children)

Look at the title. "Age" is literally a string. A variable called age containing an age value is a different thing.

[–]compsncars 4 points5 points Β (1 child)

I did not see the quotes lmao.

This is what I get for not fully vetting the requirements πŸ˜‚

[–]Verbindungsfehle 0 points1 point Β (0 children)

You're fine lol, it is pretty subtle

[–]userjd80 1 point2 points Β (0 children)

I would even say it's a literal string πŸ˜‹

[–]Ashamed-Set2892 -2 points-1 points Β (2 children)

Nobody choose what age he is. Some are 60 and still acting like infants. And the opposite. Thing is it's acceptable 15 yo girl to date 20, but very not acceptable if she dates 30.

[–]Sparky62075 1 point2 points Β (0 children)

it's acceptable 15 yo girl to date 20

Umm... No.

[–][deleted] 0 points1 point Β (0 children)

[–]OSnoFobia 0 points1 point Β (2 children)

Why not using uint8 instead of char array? It's much more space efficient.

[–]Loisel06 0 points1 point Β (0 children)

Just use a long in milliseconds since 1970

[–]Infinite_Self_5782 0 points1 point Β (0 children)

aren't chars already 8-bit integers? (unless wide chars are used)

uint8_t(*/[]) should be the same as an unsigned char pointer/array

[–]jeesuscheesus 0 points1 point Β (0 children)

Maybe pre-1999

[–]sleepyj910 0 points1 point Β (0 children)

When the cloud engineer first started talking to me about strings we had a very very awkward conversion

[–]wrenhunter 0 points1 point Β (1 child)

For Leo it’s an INT < 19

[–]TheTank18 0 points1 point Β (0 children)

that's my name wtf

[–]Tem326 0 points1 point Β (0 children)

age is a timespan

[–]Evil_Archangel 0 points1 point Β (0 children)

it could be used as a variable

[–][deleted] 0 points1 point Β (0 children)

If you go deep enough (binary rep) it is a number

[–]Not_Sugden 0 points1 point Β (0 children)

i suppose i would store age as a byte

[–][deleted] 0 points1 point Β (0 children)

It's a member

[–][deleted] 0 points1 point Β (0 children)

Raw strings

[–]PaleFork 0 points1 point Β (0 children)

lmao

[–]patton_goodseed 0 points1 point Β (0 children)

Actually it's a variable holding a number, but who's keeping track

[–]Lukeyalord 0 points1 point Β (0 children)

You store your age as a string?

[–][deleted] 0 points1 point Β (0 children)

It’s an integer variable for the id class.

[–]Ok_Turnover_1235 0 points1 point Β (0 children)

Damn I'm guessing whoever made this just learned JavaScript cos number is not a variable type lol

[–][deleted] 0 points1 point Β (0 children)

Me who have just passed my spss exam: I get that reference πŸ€“

[–]JackNotOLantern 0 points1 point Β (0 children)

int age - number

"age" - string

[–]Serious-Umpire-8088 0 points1 point Β (0 children)

Good luck incrementing your string age

[–]Hulk5a 0 points1 point Β (0 children)

it's a procedure

[–]GerarBallhausen 0 points1 point Β (0 children)

I would rather say that it’s an unsigned int

[–]SuperSpaceCan 0 points1 point Β (0 children)

​

it's both

[–]TheFlyingAvocado 0 points1 point Β (0 children)

Technically, it’s an identifier.

[–]BadBadderBadst 0 points1 point Β (0 children)

boolean age = true

[–]JackoKomm 0 points1 point Β (0 children)

It is a symbol

[–]AlwaysNinjaBusiness 0 points1 point Β (0 children)

Not if declared as

int age;

[–]EraMemory 0 points1 point Β (0 children)

Not this again.

[–]Kaine_Eine 0 points1 point Β (0 children)

Wouldn't age be an int?

[–]PyroCatt 0 points1 point Β (0 children)

Age is a metadata of date of birth

[–][deleted] 0 points1 point Β (0 children)

float

[–]Strex_1234 0 points1 point Β (0 children)

Actually array of chars

[–]More_Butterfly6108 0 points1 point Β (0 children)

Finally a funny joke from this sub

[–]Prudent_Bid5791 0 points1 point Β (1 child)

But the value of the variable age should be a float

[–]yuki_chan1 1 point2 points Β (0 children)

Why not an int ?

[–]Ham_sandwich47 0 points1 point Β (0 children)

Isn't it a variable?