Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Why null is becoming scarce (and my thoughts on it)


    Dioxin
     Share

    Recommended Posts

    This may not be exactly what you're talking about, but I know in Python, rather than if var == null you have if var is None

    Which works if you have an empty array (I think) and empty strings etc. (I haven't really tested how deep None goes in a while, forgive me if I'm mistaken)

    But personally, I like null. It's more of a personal thing though, as I like to be 100% sure that something doesn't exist.

    That and if there isn't a consistent use of what is/isn't "existing" (empty arrays, empty strings rather than just null) then soon if statements from methods end up being

    String a = yourMethodThing();

    if(a == null || a.equals("") || a.equals("null"))

     

    Thus adding more areas of "what could go wrong?" and ending up with duplicate, unnecessary code.

     

    I did enjoy reading this (I'll be honest, I skimmed a lot of it because I'm trying to get motivated to do homework and don't have time to really read it), and will probably reread it again later. (inb4 I'm completely off on what I'm talking about and now I look like a fool)

     

    Thanks for posting. :D

    Link to comment
    Share on other sites

    I doubt it. There is too much legacy software to completely get rid of null, so even if it happens it will only happen in new programming languages. Same reason why Windows 10 is called Windows 10(and not 9), because a lot of legacy programs check if the OS name starts with "windows 9" to see if the windows version is 95/98. I personally don't have a problem with null though.

    Link to comment
    Share on other sites

    Matlab has no such thing as null. It's a royal pain in the dick. Instead of != null, I have to check isempty(A). In this case, nulls are very helpful for making the programming more straight forward. there seems to be a different function for every data type to determine if it's equivalent to null. But matlab also sucks big dicks

    Link to comment
    Share on other sites

    Basic struggles of oop programmers =C Well that all depends on what you do and how you want to design it. For everyone who cannot decide, document it whether is there a chance to return a null or not and try to not return null in arrays maps etc this is such a bad idea :C

    Link to comment
    Share on other sites

    I doubt it. There is too much legacy software to completely get rid of null, so even if it happens it will only happen in new programming languages. Same reason why Windows 10 is called Windows 10(and not 9), because a lot of legacy programs check if the OS name starts with "windows 9" to see if the windows version is 95/98. I personally don't have a problem with null though.

    Of course we must account for legacy code, which is why although some newer languages don't allow them by default, you still have the option to enable them for interoperability with older languages.

     

    A lot of people actually don't mind null or see it as a problem (Eric and I had a small debate about it; it really comes down to preference). But personally, I find it to be "noise" within the program (especially null-checks). Situations where null is needed (lazy initialization to save memory or representing "nothing") can be managed in a more logical and elegant manner (a keyword for lazy initialzation, a stronger default value/type system).

     

    If you understand the concept of referencing, then NPEs make perfect sense: the developer forgot to assign a true value to a reference variable (mistake on the dev's part), so a run-time exception is thrown. I don't consider nulls bad, rather than a source of code clutter (with all the null-checks). It can definitely be managed a lot more elegantly, which other languages have given us a good example of.

     

    As we progress towards these new languages, and practices like returning an empty array instead of "nothing" become more popular, you'll find null being used less often, making it more scarce as programming progresses. I'm glad you brough that up though; nulls will always be around, even if we do advance to program without them, due to legacy code. It'll always be an option (kind of has to be), which is why I titled this "becoming scarce" rather than "the end of null" or something similar

    Matlab has no such thing as null. It's a royal pain in the dick. Instead of != null, I have to check isempty(A). In this case, nulls are very helpful for making the programming more straight forward. there seems to be a different function for every data type to determine if it's equivalent to null. But matlab also sucks big dicks

    Who said it needed to be handled through a function? As I already said, if it were to be done, it has to be done right, and Matlab is not a good example of this.

     

    The idea of getting rid of nulls is to get rid of null-checks all-together. You're saying you prefer != null over isEmpty, but you aren't realizing that you can remove the need for null-checks. Null-checks themselves are noise, and I RARELY use them myself. The only time I do use them is in a case where != null is more efficient than creating a whole new type that has the behavior of "do nothing".

     

    Yeah, NullPointerExceptions can be helpful for beginners, but as you progress you'll find yourself getting this error less-often. That's because you understand how referencing works, so you have a bunch of null-checks for the sole purpose of preventing a possible NPE. After a while, it gets extremely tedious: a new statement block and a new condition just to say do nothing if there's no value? And you have to do this anywhere a null could be used. For an experienced programmer, this can be tedious: who wants to write a whole new statement just to say "if this contains nothing, don't execute code" when it's possible to handle that implicitly? To me, that's like forcing me to extend Object each time I wanna use a class for instances, rather than for a factory or utility methods.

    Link to comment
    Share on other sites

    As we progress towards these new languages, and practices like returning an empty array instead of "nothing" become more popular, you'll find null being used less often, making it more scarce as programming progresses. I'm glad you brough that up though; nulls will always be around, even if we do advance to program without them, due to legacy code. It'll always be an option (kind of has to be), which is why I titled this "becoming scarce" rather than "the end of null" or something similar

    Who said it needed to be handled through a function? As I already said, if it were to be done, it has to be done right, and Matlab is not a good example of this.

     

    The idea of getting rid of nulls is to get rid of null-checks all-together. You're saying you prefer != null over isEmpty, but you aren't realizing that you can remove the need for null-checks. Null-checks themselves are noise, and I RARELY use them myself. The only time I do use them is in a case where != null is more efficient than creating a whole new type that has the behavior of "do nothing".

     

    Yeah, NullPointerExceptions can be helpful for beginners, but as you progress you'll find yourself getting this error less-often. That's because you understand how referencing works, so you have a bunch of null-checks for the sole purpose of preventing a possible NPE. After a while, it gets extremely tedious: a new statement block and a new condition just to say do nothing if there's no value? And you have to do this anywhere a null could be used. For an experienced programmer, this can be tedious: who wants to write a whole new statement just to say "if this contains nothing, don't execute code" when it's possible to handle that implicitly? To me, that's like forcing me to extend Object each time I wanna use a class for instances, rather than for a factory or utility methods.

     

    I think you misunderstood my example:

     

    If I'm grabbing files through uigetfile, it has a chance of returning empty, which in the java case would be nulled. I need to check if it's empty to decide whether to continue execution. The function call would be there regardless. It would be much easier to compare to null, which would work for all data types and not just cells (isempty). Matlab is also built on the java vm, so it's possible to use java datatypes, but the null issue still screws everything up. Matlab sucks and I hate using it every day. Where I can, I build classes in java and run them though matlab for increases in efficiency.

    Link to comment
    Share on other sites

    I think you misunderstood my example:

     

    If I'm grabbing files through uigetfile, it has a chance of returning empty, which in the java case would be nulled. I need to check if it's empty to decide whether to continue execution. The function call would be there regardless. It would be much easier to compare to null, which would work for all data types and not just cells (isempty). Matlab is also built on the java vm, so it's possible to use java datatypes, but the null issue still screws everything up. Matlab sucks and I hate using it every day. Where I can, I build classes in java and run them though matlab for increases in efficiency.

    I actually just talked to my friend about this, who said something similar: "An API could return null, what would you do in that case?"

     

    A lot of APIs still use null as a value. In these cases, you need a null-check, and yeah != null is more elegant (and even more efficient) than an ifEmpty method call.

     

    APIs that return null require null checks. But if the API instead returned a value that had the behavior of "do nothing", which doing nothing is what you intend to happen, then a null check is not needed at all. Its not about replacing null-checks with another form of checking if something is empty, rather than replacing null all together, removing the need for null-checks

    Link to comment
    Share on other sites

    I actually just talked to my friend about this, who said something similar: "An API could return null, what would you do in that case?"

     

    A lot of APIs still use null as a value. In these cases, you need a null-check, and yeah != null is more elegant (and even more efficient) than an ifEmpty method call.

     

    APIs that return null require null checks. But if the API instead returned a value that had the behavior of "do nothing", which doing nothing is what you intend to happen, then a null check is not needed at all. Its not about replacing null-checks with another form of checking if something is empty, rather than replacing null all together, removing the need for null-checks

    What's the point of that though? All it does is change null to something else, that's like completely deprecating the String class and replacing it with the ALL NEW SuperString class, which does exactly the same.. I don't see why null would have to be replaced if all it's going to be is a giant bitch.

    Link to comment
    Share on other sites

    I actually just talked to my friend about this, who said something similar: "An API could return null, what would you do in that case?"

     

    A lot of APIs still use null as a value. In these cases, you need a null-check, and yeah != null is more elegant (and even more efficient) than an ifEmpty method call.

     

    APIs that return null require null checks. But if the API instead returned a value that had the behavior of "do nothing", which doing nothing is what you intend to happen, then a null check is not needed at all. Its not about replacing null-checks with another form of checking if something is empty, rather than replacing null all together, removing the need for null-checks

     

    You still need a check to continue - that's what my point is. If I'm going to check, I'd rather it be null, rather than expensive CPU cycles for something that could be iterated trillions of times during a simulation

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.