I saw this cartoon. I know what `!!` is of course....
# getting-started
e
I saw this cartoon. I know what
!!
is of course. Is
??
a thing, or is my strategy of learning programming languages from r/ProgrammerHumor misguided?
s
is my strategy of learning programming languages from r/ProgrammerHumor misguided?
lmao
??
isn't really a thing in Kotlin I don't think? like
T??
is syntactically valid but resolves to
T?
so ¯\_(ツ)_/¯
??
is sometimes the null-coalescing operator in other languages (Swift and C# come to mind), but we use
?:
for that so I'm not sure what they mean
e
@Shawn Next thing you're going to tell me is that I can't trust AI:
🤣 5
🔥 1
Seriously, I'm glad you got my sense of humor and thank you for the information.
👍 1
s
Might also be worth mentioning that
!!
is the least of your worries—platform types, inheritance, and improper passing of
this
in an
init
block or similar usage are all much more likely to cause Kotlin NPEs
e
I'm teaching CS 1 in Kotlin and like to share memes with my students. I'm currently working on a lecture on Null and Nullability (one of Jane Austen's lesser known works). What are the issues with inheritance? (Despite posting to this channel, I'm fairly experienced in Kotlin but like to double-check things sometimes.)
s
Null and Nullability is good lol
the inheritance problem is the same as it is in Java or really almost any language that allows for it—a superclass that accesses a field that needs to be implemented/populated by a subclass before the subclass has been able to do so will necessarily cause an NPE
and
kotlinc
doesn't have robust enough validation around that unfortunately
e
Got it, so I won't claim that Kotlin offers null-safety, just that it is safer than Java.
s
I mean, it offers much more null safety than Java
👍 3
Without starting to ramble, one of the more frustrating challenges of pedagogy is conveying to students that we rely on systems (type checker, compiler, etc) that have rules, and those rules are helpful and keep us safe the vast majority of the time, but yes, still, technically they can be skirted around with bad practice or malicious intent, but that doesn't mean they can't be relied upon at all
👍 3
you never want to tell them "oh don't worry about it" or like "don't ask questions", but at the outset it's just not helpful for them to have to interrogate the fundamentals of something so lofty and complex
e
I realize that I need to explain to students what "compile-time" means because errors get reported as they type code into the IDE, not when the code is explicitly being compiled.
s
lol yes, IDEs do blur the line there
e
That reminds me that I need to add this cartoon. (I'm getting to be an old lady and often talk about how things have changed.)
1
🤣 5
y
One way to think of
SomeType?
In Kotlin is that it's very similar to an
Option<SomeType>
in other languages. Null dereferencing has to be explicit, we just use
!!
For that, while other languages have other constructs (e.g. I think Rust uses
unwrap
or something like that). Kotlin absolutely offers null-safety, but it can't easily prevent you from accessing potentially uninitialized data. The fact that uninitialized data happens to be represented by
null
is practically implementation detail.
👍 1
s
so yes, Kotlin's null-safety isn't sound (even without platform-types) but practically I only had a single NullPointerException in 6 years. And the kind of NullPointer it does produce isn't due to unexpected data, but due to setup/configuration using unsound patterns (like the superclass constructor trying to use a property that hasn't been initialised yet) so it tends to blow up every single time, so it's easy to find/fix.
👍 1
a
@Ellen Spertus love the theme, you may want to work in a reference to https://en.wikipedia.org/wiki/Sense_and_Sensibility_and_Sea_Monsters which was a less-successful followup to Pride & Prejudice & Zombies (the book, far better than the movie)
🐉 1
e
Maybe I'll ask an AI to write the novel. @Andy Dent
From claude.ai:
Summary: "Null and Nullability" is a satirical romance set in the fictional town of Bitshire. The story follows the clever and spirited Miss Ada Lovelace, a young woman with an uncommon passion for mathematics and logic. When the mysterious and wealthy Mr. Charles Babbage arrives in town, Ada finds herself torn between her growing affection for him and her desire to prove her worth in a field dominated by men. As she navigates the complex social algorithms of Regency-era England, Ada must determine whether her heart is truly nullable or if Mr. Babbage might be the one to assign it a value.
Excerpt: It is a truth universally acknowledged that a single man in possession of a good fortune must be in want of a wife. However, the wishes of such a man upon entering a neighbourhood are seldom considered by those eager to see him wed.
Miss Ada Lovelace stood by the window of her father's study, her fingers idly tracing the outline of a complex equation etched into the glass. The rumours of Mr. Charles Babbage's arrival in Bitshire had set the town atwitter, but Ada found herself more intrigued by the whispers of his revolutionary calculating machine than by speculation about his yearly income.
"My dear Ada," her mother's voice rang out as she entered the room, "you cannot mean to greet our new neighbour in such a state! Your hair is positively null, and your dress is in dire need of initialization."
Ada sighed, turning from her contemplation of prime numbers to face her mother's scrutiny. "Mama, I assure you, my appearance is perfectly adequate for any rational being. Besides, I doubt Mr. Babbage will be evaluating my suitability based on the state of my coiffure."
Mrs. Lovelace tutted disapprovingly. "Oh, you impossible girl! When will you learn that a young lady's prospects are not determined by the capacity of her mind, but by the charm of her manner and the elegance of her attire?"
"Perhaps," Ada replied with a wry smile, "when the gentlemen of our acquaintance learn to value a woman for more than her ability to pour tea and recite sonnets. Until then, I shall continue to cultivate my intellect, even if it renders me null and void in the eyes of society."
As her mother launched into another lecture on the importance of securing a suitable match, Ada's thoughts drifted back to the fascinating rumours of Mr. Babbage's invention. Little did she know that their impending meeting would set in motion a series of events that would challenge everything she thought she knew about logic, love, and the nullability of the heart.
😱 1
o
@Ellen Spertus Hello, please don't use the term "null safety" when referring to Kotlin in front of your students. Instead use the term "denotable nullability", i.e. "the ability to denote whether a variable can be null at the language level". I'd recommend that everyone else in this thread stop using the term as well. It's just as misleading as calling
val
an "immutable variable" which some people still keep saying after all these years. It is just a "read-only property" - i.e. the reference cannot be reassigned. Which says nothing about the mutability of the referenced object. Terminology is important.
🙏 1
k
At least it's not as bad as some languages that have
const var
, the self-contradictory "constant variable".
‼️ 1