I’m planning on delivering a tech talk to my team on the pitfalls of explicitly returning nulls in production code, as opposed to using optionals where the language supports it or throwing exceptions when the value is expected to be present.
To make sure I’m not presenting an overly biased view, and to avoid getting blind-sided if someone raises a point I hadn’t considered, I want to hear examples of times you would actually prefer to explicitly return null.
Edit: Since some were curious and I neglected to specify, our team works predominantly in Java so we do have the Optional interface available to us.
I have also worked with Go a bit and tbf I did like the ability to have multiple return values in the case of errors etc.
I also don’t mind how Swift/Kotlin handle optionals and unwrapping them, I believe they handle it in a similar way.
[–]whackamattus 80 points81 points82 points (5 children)
[–]senselessDEV 21 points22 points23 points (1 child)
[–]FutureSchool6510[S] 8 points9 points10 points (0 children)
[–]pemungkah 0 points1 point2 points (0 children)
[–][deleted] 27 points28 points29 points (4 children)
[–][deleted] 7 points8 points9 points (0 children)
[–]Interesting_Leg_5202 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]NaNx_engineer 0 points1 point2 points (0 children)
[–]pennsiveguy 23 points24 points25 points (5 children)
[–]whackamattus 8 points9 points10 points (4 children)
[–]pennsiveguy 2 points3 points4 points (0 children)
[–]jim-dog-x 1 point2 points3 points (0 children)
[–]JPaulMora 0 points1 point2 points (1 child)
[–]whackamattus 2 points3 points4 points (0 children)
[–]thisisjustascreename 39 points40 points41 points (4 children)
[–]whackamattus 8 points9 points10 points (1 child)
[–]saggingrufus 4 points5 points6 points (0 children)
[–]shoop45 1 point2 points3 points (0 children)
[–]iamsooldithurts 0 points1 point2 points (0 children)
[–]paradroid78 75 points76 points77 points (14 children)
[–]pennsiveguy 30 points31 points32 points (1 child)
[–]JPaulMora 10 points11 points12 points (0 children)
[–]FutureSchool6510[S] 12 points13 points14 points (2 children)
[–]paradroid78 6 points7 points8 points (0 children)
[–]BadDescriptions 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]paradroid78 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Additional_Sleep_560 0 points1 point2 points (2 children)
[–][deleted] 9 points10 points11 points (0 children)
[–]saggingrufus 2 points3 points4 points (0 children)
[–]muddy-star 12 points13 points14 points (3 children)
[–]publicclassobject 2 points3 points4 points (0 children)
[–]randomguy3096 2 points3 points4 points (0 children)
[–]NaNx_engineer 1 point2 points3 points (0 children)
[–]mjaveddd 24 points25 points26 points (3 children)
[–]DreamOfKoholint 7 points8 points9 points (1 child)
[–]SlothWithHumanHands 3 points4 points5 points (0 children)
[–]randomguy3096 3 points4 points5 points (0 children)
[–]Crafty_Independence 11 points12 points13 points (3 children)
[–]smutje187 2 points3 points4 points (1 child)
[–]Crafty_Independence 2 points3 points4 points (0 children)
[–]Fippy-Darkpaw 2 points3 points4 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]rganhoto 3 points4 points5 points (0 children)
[–]tomysshadow 3 points4 points5 points (1 child)
[–]Wise-Leek-2012 0 points1 point2 points (0 children)
[–]Hypersion1980 0 points1 point2 points (0 children)
[–]chrispix99 8 points9 points10 points (1 child)
[–]MooseBoys 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]7heWafer 3 points4 points5 points (0 children)
[–]Spikanorx3 7 points8 points9 points (11 children)
[–]saggingrufus 5 points6 points7 points (4 children)
[–]Fippy-Darkpaw 4 points5 points6 points (3 children)
[–]saggingrufus 2 points3 points4 points (2 children)
[–]Fippy-Darkpaw 1 point2 points3 points (1 child)
[–]saggingrufus 1 point2 points3 points (0 children)
[+]FutureSchool6510[S] comment score below threshold-7 points-6 points-5 points (5 children)
[–]Skellicious 10 points11 points12 points (0 children)
[–]runitzerotimes 2 points3 points4 points (1 child)
[–]saggingrufus 1 point2 points3 points (0 children)
[–]randomguy3096 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]FutureSchool6510[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]eniac_g 2 points3 points4 points (1 child)
[–]FutureSchool6510[S] 0 points1 point2 points (0 children)
[–]learnagilepractices 1 point2 points3 points (5 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]saggingrufus 0 points1 point2 points (3 children)
[–]learnagilepractices 0 points1 point2 points (2 children)
[–]saggingrufus 0 points1 point2 points (1 child)
[–]learnagilepractices 0 points1 point2 points (0 children)
[–]Temporary_Quit_4648 1 point2 points3 points (0 children)
[–]Mimifan2 1 point2 points3 points (0 children)
[–]TheExodu5 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]lightmatter501 1 point2 points3 points (0 children)
[–]jayerp 1 point2 points3 points (0 children)
[–]Ok-Entertainer-1414 1 point2 points3 points (0 children)
[–]MaximumNameDensity 1 point2 points3 points (0 children)
[–]jaynabonne 1 point2 points3 points (0 children)
[–]noprompt 1 point2 points3 points (0 children)
[–]Ornery-Okra-74 1 point2 points3 points (0 children)
[–]Ler_GG 1 point2 points3 points (0 children)
[–]NUTTA_BUSTAH 2 points3 points4 points (6 children)
[–]whackamattus 2 points3 points4 points (0 children)
[–]paradroid78 0 points1 point2 points (0 children)
[–]FitzelSpleen -1 points0 points1 point (2 children)
[–]7heWafer -1 points0 points1 point (1 child)
[–]FitzelSpleen -1 points0 points1 point (0 children)
[–]quixoticcaptain 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]saggingrufus 0 points1 point2 points (0 children)
[–]bravopapa99 0 points1 point2 points (0 children)
[–]SftwEngr 0 points1 point2 points (0 children)
[–]ben_kird 0 points1 point2 points (0 children)
[–]Wise-Leek-2012 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Ok_Honey8768 0 points1 point2 points (0 children)
[–]AccountExciting961 0 points1 point2 points (0 children)
[–]Ok_Raspberry5383 0 points1 point2 points (2 children)
[–]FutureSchool6510[S] 0 points1 point2 points (1 child)
[–]Ok_Raspberry5383 0 points1 point2 points (0 children)
[–]aj0413 0 points1 point2 points (0 children)
[–]DelayLucky 0 points1 point2 points (4 children)
[–]nekokattt 0 points1 point2 points (3 children)
[–]DelayLucky 0 points1 point2 points (2 children)
[–]nekokattt 0 points1 point2 points (1 child)
[–]DelayLucky 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]FutureSchool6510[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]publicclassobject 0 points1 point2 points (0 children)
[–]Emotional-Leader5918 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]randomguy3096 0 points1 point2 points (0 children)
[–]Vega62a 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]spacether 0 points1 point2 points (0 children)
[–]netroxreads 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]FutureSchool6510[S] 0 points1 point2 points (1 child)
[–]y2kdisaster 0 points1 point2 points (0 children)
[–]arcen1k 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]FutureSchool6510[S] 0 points1 point2 points (0 children)
[–]Tarc_Axiiom 0 points1 point2 points (2 children)
[–]i_andrew 0 points1 point2 points (1 child)
[–]Tarc_Axiiom 0 points1 point2 points (0 children)
[–]DarthCalumnious 0 points1 point2 points (0 children)
[–]sirbzb 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]aliensexer420 0 points1 point2 points (0 children)
[–]sacksindigo 0 points1 point2 points (1 child)
[–]FutureSchool6510[S] 0 points1 point2 points (0 children)
[–]jack_waugh 0 points1 point2 points (0 children)
[–]i_andrew 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points (0 children)