Hack Forums
Strict Types vs No Types - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: Strict Types vs No Types (/showthread.php?tid=6269305)

Pages: Pages 1 2


Strict Types vs No Types - Hackers - Apr 23, 2024

Do you prefer strict types in your code, or no types? Do you sometimes use them & sometimes not?

I prefer the strict types lately, but there was a time where I obviously enjoyed not defining them. The reason I like them is because it keeps everyone calm, reasonable, and mentally stable. Defined types in your code help you come back later, jump into someone else's code with easy input/output expectations, etc.

Something I do see a lot though is devs using interesting fallbacks, such as false, null, or (the worst) undefined.
For example, many people give "missing string" values a default of NULL, or False, which is a different type than 'string', and others may even use the word "false" inside of a string, especially if they are forced to stick to strings... I don't like that either for obvious reasons.



One exception may be if you want to track whether a user has entered something (string), chose to enter nothing (empty string), or hasn't had a chance to enter anything (empty string?) - the reason I use this example is because it came up in a social app I built:

How do you track "we asked the user & they entered nothing" versus "we have not asked the user to enter anything yet" ?

Well, if you are using empty string "" for your "none/false/empty" state, there is no way to track that info without either another column in the database somewhere, another method of knowing, OR a different value type (using string for entered data / no data, and NULL for when user hasn't had chance yet).

For those of you with experience in certain DB engines, you are most likely familiar with "default NULL" and how that can be applied to different type columns... and you probably also know that it can either be the biggest blessing, or biggest curse on a codebase depending on scale.

I'll stand by my original point that strict types are important & if I could go back we probably would've not used NULL in that specific scenario, or at very least maybe someone should have asked "do we REALLY need to know if a user was presented with this specific field?" - in that case, the answer was No. Whoever made that original decision neglected to think about how they could simply use the notifications system (of the social app) to re-trigger notifications for "missing data" and there was never a need for that field to track its own "state" (of whether user was told to enter it) in its own field.


RE: Strict Types vs No Types - nucleo_type09 - Apr 23, 2024

(Apr 23, 2024 03:32 PM)nodes Wrote:  Do you prefer strict types in your code, or no types? Do you sometimes use them & sometimes not?

I prefer the strict types lately, but there was a time where I obviously enjoyed not defining them. The reason I like them is because it keeps everyone calm, reasonable, and mentally stable. Defined types in your code help you come back later, jump into someone else's code with easy input/output expectations, etc.

Something I do see a lot though is devs using interesting fallbacks, such as false, null, or (the worst) undefined.
For example, many people give "missing string" values a default of NULL, or False, which is a different type than 'string', and others may even use the word "false" inside of a string, especially if they are forced to stick to strings... I don't like that either for obvious reasons.



One exception may be if you want to track whether a user has entered something (string), chose to enter nothing (empty string), or hasn't had a chance to enter anything (empty string?) - the reason I use this example is because it came up in a social app I built:

How do you track "we asked the user & they entered nothing" versus "we have not asked the user to enter anything yet" ?

Well, if you are using empty string "" for your "none/false/empty" state, there is no way to track that info without either another column in the database somewhere, another method of knowing, OR a different value type (using string for entered data / no data, and NULL for when user hasn't had chance yet).

For those of you with experience in certain DB engines, you are most likely familiar with "default NULL" and how that can be applied to different type columns... and you probably also know that it can either be the biggest blessing, or biggest curse on a codebase depending on scale.

I'll stand by my original point that strict types are important & if I could go back we probably would've not used NULL in that specific scenario, or at very least maybe someone should have asked "do we REALLY need to know if a user was presented with this specific field?" - in that case, the answer was No. Whoever made that original decision neglected to think about how they could simply use the notifications system (of the social app) to re-trigger notifications for "missing data" and there was never a need for that field to track its own "state" (of whether user was told to enter it) in its own field.

always strict types for me, i think, correct me if im wrong, having no strict types is just like playing russian roulette, if it goes it goes, if not your **** haha, also because having NULL types is useless, is like reserving a space in the fridge for air haha, what u think? is this a good analogy?😵


RE: Strict Types vs No Types - JohnFitzgeraldKennedy - Apr 23, 2024

My preference is in the "strict" typing camp, generally speaking. IMO, good code should be as explicit as possible about things like data types because A) it helps prevent bugs and B) its easier to read/understand (for me at least). I would take old school strictly typed Java over Python any day (haters gunna hate).

I really dislike languages that infer/convert typing at runtime, its my biggest pet peeve about languages and I avoid using languages that do this where I can (JS, php, etc.)


RE: Strict Types vs No Types - laurellance269 - Apr 23, 2024

I'd say strict types are better. No types are nice, fine, and satisfying at the beginning, but they're a PITA as codebase matures.


RE: Strict Types vs No Types - nucleo_type09 - Apr 24, 2024

(Apr 23, 2024 05:18 PM)JohnFitzgeraldKennedy Wrote:  My preference is in the "strict" typing camp, generally speaking. IMO, good code should be as explicit as possible about things like data types because A) it helps prevent bugs and B) its easier to read/understand (for me at least). I would take old school strictly typed Java over Python any day (haters gunna hate).

I really dislike languages that infer/convert typing at runtime, its my biggest pet peeve about languages and I avoid using languages that do this where I can (JS, php, etc.)

me too man, i used to code using php once ago, but it was not my thing, i also used python for a while at the very beginning, but was only a couple of months thing haha :), that was the worst thing i saw in programming, Python DT absence....😵

(Apr 23, 2024 08:02 PM)laurellance269 Wrote:  I'd say strict types are better. No types are nice, fine, and satisfying at the beginning, but they're a PITA as codebase matures.

yeah, i would say a the beginning when you don't know what you doing no types are better because is easier, but once you learn, then you cannot live without them... i mean.. you can't sleep at night bro 🙃


RE: Strict Types vs No Types - Dirty - Apr 25, 2024

Strict types, and I don't believe there's much of an argument here. It helps you reason about the code in front of you and that's all you need.
Through being able to more efficiently reason about code you can hold more/more complex context in your head mentally and in my opinion that's one of the main skills together with debugging that coding is about. Patterns and syntax and all these other things people spend a lot of time is all good theoretically, but if you can't fix bugs or


RE: Strict Types vs No Types - nucleo_type09 - Apr 25, 2024

(Apr 25, 2024 02:14 AM)Dirtybox Wrote:  Strict types, and I don't believe there's much of an argument here. It helps you reason about the code in front of you and that's all you need.
Through being able to more efficiently reason about code you can hold more/more complex context in your head mentally and in my opinion that's one of the main skills together with debugging that coding is about. Patterns and syntax and all these other things people spend a lot of time is all good theoretically, but if you can't fix bugs or

what i was also thinking haha, true, one of the most important skills in a programmer mind is the ability to handle strict types at all times, this is what elevates you from beginner/mid-level to advanced, for instance, i know this will cause haters to spit on me, but python is just about beginner language, no types at all, r u kidding me? why would you cut off the strict types and complexity of programming if challenge is the main reason most of us want to code, programming is about challenging yourself, and your capabilities, back in the day "even tho im gen-z lol", but i know back in the day people used to code just for the challenge of it, they wanted to show off how smart they were, and how good they were at what they were doing, i honestly doubt programming was about money back in the day, look at hackers back then, why do you think they were hacking? money? nah, there was no profit at all, all viruses and malware were about showing your abilities, like "look what i can do and you can't", nowdays malware is just about money and profit, that's why we are getting worst at them, if it wasn't for all those internet archives and youtube tutorials there will be not even 10% of hackers/programmers today, is just "yeah bro, learn to code and get paid 10k a month", blah, that mindset really is the worst thing happened in the field in the last 20 years, do you think there will be someone hacking and coding if there wasn't all those tools available like metalsploit for example? or all those libraries available to make programming easier? or maybe even like python where you don't even need to know what data type you are using at all? what do u think a python dev would do if challenged to rewrite the same thing he did using python in c++? haha, sorry if i made any grammar errors bro, english is not my best...😵


RE: Strict Types vs No Types - happygonutty - Apr 25, 2024

(Apr 25, 2024 04:07 AM)nucleo_type09 Wrote:  what i was also thinking haha, true, one of the most important skills in a programmer mind is the ability to handle strict types at all times, this is what elevates you from beginner/mid-level to advanced, for instance, i know this will cause haters to spit on me, but python is just about beginner language, no types at all, r u kidding me? why would you cut off the strict types and complexity of programming if challenge is the main reason most of us want to code, programming is about challenging yourself, and your capabilities, back in the day "even tho im gen-z lol", but i know back in the day people used to code just for the challenge of it, they wanted to show off how smart they were, and how good they were at what they were doing, i honestly doubt programming was about money back in the day, look at hackers back then, why do you think they were hacking? money? nah, there was no profit at all, all viruses and malware were about showing your abilities, like "look what i can do and you can't", nowdays malware is just about money and profit, that's why we are getting worst at them, if it wasn't for all those internet archives and youtube tutorials there will be not even 10% of hackers/programmers today, is just "yeah bro, learn to code and get paid 10k a month", blah, that mindset really is the worst thing happened in the field in the last 20 years, do you think there will be someone hacking and coding if there wasn't all those tools available like metalsploit for example? or all those libraries available to make programming easier? or maybe even like python where you don't even need to know what data type you are using at all? what do u think a python dev would do if challenged to rewrite the same thing he did using python in c++? haha, sorry if i made any grammar errors bro, english is not my best...😵

I would definitely go with strict types as well as I believe it is what makes you become a more stronger programmer and become more enthusiastic with cyber security which would allow you to become more strict on applying programming in real life making you more effective, efficient and producing well organized and structured outputs.

I look at programming languages without data type declaration (except those with optional) as inferior and paper with too many holes.


RE: Strict Types vs No Types - nucleo_type09 - Apr 25, 2024

(Apr 25, 2024 04:25 PM)happygonutty Wrote:  I would definitely go with strict types as well as I believe it is what makes you become a more stronger programmer and become more enthusiastic with cyber security which would allow you to become more strict on applying programming in real life making you more effective, efficient and producing well organized and structured outputs.

I look at programming languages without data type declaration (except those with optional) as inferior and paper with too many holes.

Same, idk if you feel the same, but i feel bored whenever i use langs like js or python or even php, they haven't that vibe u know? the vibe that complex challenges low level PLs give u, idk, its just another thing... haha


RE: Strict Types vs No Types - happygonutty - Apr 25, 2024

(Apr 25, 2024 04:33 PM)nucleo_type09 Wrote:  Same, idk if you feel the same, but i feel bored whenever i use langs like js or python or even php, they haven't that vibe u know? the vibe that complex challenges low level PLs give u, idk, its just another thing... haha

And now you know the reason why I am strongly against PHP. For JavaScript I prefer TypeScript. Python, well I always put the optional types as much as possible.


RE: Strict Types vs No Types - nucleo_type09 - Apr 25, 2024

(Apr 25, 2024 04:35 PM)happygonutty Wrote:  And now you know the reason why I am strongly against PHP. For JavaScript I prefer TypeScript. Python, well I always put the optional types as much as possible.

i've used both php, js/ts, python and even other langs like [rust, assembly(x86-64), perl, go, bs, sql, java], but the only 1 that stood out to me was c++, idk, it has something different, something with those pointers and references that catched me 😵😵, i didn't learn too many langs because im stuck with c++ since i found out how good it is...


RE: Strict Types vs No Types - happygonutty - Apr 25, 2024

(Apr 25, 2024 04:47 PM)nucleo_type09 Wrote:  i've used both php, js/ts, python and even other langs like [rust, assembly(x86-64), perl, go, bs, sql, java], but the only 1 that stood out to me was c++, idk, it has something different, something with those pointers and references that catched me 😵😵, i didn't learn too many langs because im stuck with c++ since i found out how good it is...

C++ is in deed good and by far kind of superior and close to assembly language. You can also say C++ is just superior version of C as syntax almost the same, just with classes. I would definitely opt to C++ as well if its quite important but nowadays I am switching to Rust though I still respect C++ and I am still using C++ for software related applications that I am currently working on especially with Qt Framework and Win32 APIs from MSDN for my customers.


RE: Strict Types vs No Types - nucleo_type09 - Apr 25, 2024

(Apr 25, 2024 04:50 PM)happygonutty Wrote:  C++ is in deed good and by far kind of superior and close to assembly language. You can also say C++ is just superior version of C as syntax almost the same, just with classes. I would definitely opt to C++ as well if its quite important but nowadays I am switching to Rust though I still respect C++ and I am still using C++ for software related applications that I am currently working on especially with Qt Framework and Win32 APIs from MSDN for my customers.

how do u see rust syntax? bro i gotta tell you, that thing is horrible, i might be weird saying the following but that's what i think, i can't code using a language that has horrible syntax and no strict types, when i code, i see my own code as a Symphony like mozart Great G minor Symphony, if i look at my code and i don't like the flow it follows, then im not satisfied at all, sometimes, i coding really gives me reason to wake up, i feel like im composing the "Great G minor" from Mozart haha, is that weird? i dont see my code as just code, but as some kind of personal signature, by someone's code you can see what that person feels, what that person has in mind, even how brilliant a person can be, of course if the code is ugly, the person who wrote it doesn't give a shit about his own code symphony, another thing i like, is to write my code by myself, because if it gets a team to write it, i can't say it was mine, u know what i mean? weird stuff man, sometimes i think im burned haha


RE: Strict Types vs No Types - happygonutty - Apr 25, 2024

(Apr 25, 2024 04:59 PM)nucleo_type09 Wrote:  how do u see rust syntax? bro i gotta tell you, that thing is horrible, i might be weird saying the following but that's what i think, i can't code using a language that has horrible syntax and no strict types, when i code, i see my own code as a Symphony like mozart Great G minor Symphony, if i look at my code and i don't like the flow it follows, then im not satisfied at all, sometimes, i coding really gives me reason to wake up, i feel like im composing the "Great G minor" from Mozart haha, is that weird? i dont see my code as just code, but as some kind of personal signature, by someone's code you can see what that person feels, what that person has in mind, even how brilliant a person can be, of course if the code is ugly, the person who wrote it doesn't give a shit about his own code symphony, another thing i like, is to write my code by myself, because if it gets a team to write it, i can't say it was mine, u know what i mean? weird stuff man, sometimes i think im burned haha

Lol! Hahahaha. I guess you are more of a composer than a musician when it comes to programming. Truthfully speaking, Rust really has horrible syntax (even though I use it) despite the optimized performance and so. All I can see right now is that you are a dev who is looking for enriched features and syntax, like yo everything should be perfect! But in my case, I am dev looks only for enriched features and syntax doesn't matter to me. As long as everything works according to my plan, execution wise it doesn't bottleneck and the syntax has strict and concise features then I have no problems with it. 😆


RE: Strict Types vs No Types - nucleo_type09 - Apr 26, 2024

(Apr 25, 2024 05:49 PM)happygonutty Wrote:  Lol! Hahahaha. I guess you are more of a composer than a musician when it comes to programming. Truthfully speaking, Rust really has horrible syntax (even though I use it) despite the optimized performance and so. All I can see right now is that you are a dev who is looking for enriched features and syntax, like yo everything should be perfect! But in my case, I am dev looks only for enriched features and syntax doesn't matter to me. As long as everything works according to my plan, execution wise it doesn't bottleneck and the syntax has strict and concise features then I have no problems with it. 😆

a composer? 😆 that one is better of a term... yeah i can say that, bro did you notice how we've gono from "strict types vs no types" to "code is like" here 🤣 i think we're a bit "out of scope" haha, that poor OP just wanted to know if we like strict types or no types and we provided him with Mozart hahaha