|
It makes no sense to me. Maybe it's like an assert, in which case it should read "should only be used in situations where you are certain that the value should not be null".
|
|
|
|
|
Presumably it's to make it absolutely obvious that you wanted the app to crash when it was null!
"Nope, this wasn't no accident. I hate my users."
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Shouldn't it be?
val length = username!!.length
"The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012
|
|
|
|
|
Yes!! It's fixed. Thanks for pointing it out.
Get me coffee and no one gets hurt!
|
|
|
|
|
It says in the Kotlin docs that it is used to test for and throw NullPointerException. So, I guess as a null safety mechanism, it's there if you want it.
|
|
|
|
|
I suppose that makes sense (I think )
Get me coffee and no one gets hurt!
|
|
|
|
|
Maybe it's similar to the "null-forgiving" operator in newer versions of C#, in that it's only used to suppress a compiler warning?
! (null-forgiving) operator - C# reference | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Avoid using the !! assertion in Kotlin - it is generally not recommended because you are bypassing the compiler safety rules.
From the compiler's point of view, if something is nullable - even if you know it currently is not null - you need to cover for the possibility that it may be null when it is referenced.
What is recommended is something like this:
foo?.let{
do something with foo
}
This tells the compiler that when foo(which is nullable) is not null you want to "do something with foo".
...and there's lots in Kotlin that I found and still at times find difficult having come from a C# .NET background.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Thinking about it a bit more, I think you should be able to use the Elvis operator, which in this case will assign a length of 0 if the username is null:
val length = username?.length ?: 0
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
In C languages (including Java) asserts were supposed to crash the program if they ever evaluated to false.
Not something you would want to use if it ever could be null.
And asserts should never include side effect logic. Part of the primitive toolset that led to “Contract” based programming .
|
|
|
|
|
I have a header file that is just tables of possible/must/must-not break actions depending on character combinations.
This is due to Unicode Standard Annex 14 and Unicode Standard Annex 29. Presumably because the committee hadn't made things difficult enough already, they decided to turn line breaking into a Rube Goldberg contraption.
I'm sure they have reasons for all of this, and if they could corner me in a dark alley they'd explain them to me at length, but at the end of the day coding against the Unicode standards is like flossing a cat - everybody ends up unhappy and someone might be going to the emergency room.
I wish I could have just used OpenType.
Real programmers use butterflies
|
|
|
|
|
I'm impressed (14; 29).
Like finding the missing appendix (that no one else seems to be aware of) from an old PDF that's been circulating. I did; and it made all the difference in understanding the main body.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Somebody should have said: 64 characters is enough for anyone.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Worse than Vogons: Humans trying to defined rules for the royal mess other humans managed to create over many years.
You can choose only supporting English. Or do Chinese - even simpler.
Once you want to support multiple languages you end up in the mess. And don't expect you can do proper line-breaks without knowing the language of the UI. A Chinese text with an English word in it (for example a company name) should use Chinese line-break rules inside the English word. I would expect you can put western languages into the same rule set (as long as you respect non-breakable space etc) without too many problems.
|
|
|
|
|
Yeah, I'm aware the line breaking is language specific. Fortunately, EPUBs always indicate the language they are in. It's more just that the code is big, ugly, slow, and incomprehensible.
Real programmers use butterflies
|
|
|
|
|
So you want to do a Dutch accent. I get it, it's a funny accent to make fun of. But there is one feature that Dutch doesn't have: sh everywhere. That's a rare sound in Dutch. It mainly exists English loan words, that's right, you are the ones saying sh. In actual Dutch words, there are some rare cases where an s-j combo can assimilate into the sh sound (such as the name Sjaak) but that's not a phoneme.
"But I hear you guys saying that sh sound" you might say. You're not hearing it. What you're hearing is a retracted s, which has a lower pitch, but it doesn't really have that "shushing" sound of an sh. It's not produced by blowing air between the tongue and the roof of the mouth, so it's not an sh. Only the tip of the tongue should go up, near the alveolar ridge. Go practice, or use a regular plain old English s, but sh sounds extremely non-Dutch.
|
|
|
|
|
So who are all these CodeProject geeks who are making fun of your language? Shander Rossel[^] maybe?
|
|
|
|
|
Shirley you meant Shander Rosshel.
|
|
|
|
|
There's a double "s", so it's actually Shander Roshshell.
|
|
|
|
|
3rd times the charm!
|
|
|
|
|
Well, I'm Dutch, and I think Dutch is a terrible language
|
|
|
|
|
Are you mocking my lishp?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Why is there an s in lisp it's so unfair
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|
|
Why is disleck... dysslekc... dyslexia so hard to spell?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have sex daily dyslexia
"I didn't mention the bats - he'd see them soon enough" - Hunter S Thompson - RIP
|
|
|
|