Re:Java is not a safe language
by Jenkins2000 on Monday June 13, 2022 @03:38PM
(#31730636)
My solution is to convert to Kotlin, I can't stand working on Java anymore:
customer?.order?.lineItemList?.forEach { item -> val currency = item?.product?.price?.currency
Re:Java is not a safe language
by commandlinefan on Monday June 13, 2022 @04:38PM
(#31731473)
If I'm understanding this correctly, it's still a problem: if the product's price element or the order's line item list is null, for example, that shouldn't just be silently ignored. The transaction should fail, loudly and visibly (like with an exception) so that the root cause of the invalid data can be examined. The way most programmers code it is to just ignore the bad data and potentially ship an item for free, or without charging tax, or charge the customer but not ship the item, etc. etc. This is why so many software development organizations have huge QA departments.
Re:Java is not a safe language
by Jenkins2000 on Monday June 13, 2022 @08:34PM
(#31733438)
I still write null checks if needed but for deeply nested objects, it comes down to only checking for null at the end of the chain instead of in Java where you have null checks each step of the way.
You can chain Optional exactly the same as Kotlin but without the syntay suger ofc.
There is so much wrong with this code...
Re:Java is not a safe language
by commandlinefan on Monday June 13, 2022 @01:03PM
(#31728303)
And I've given up arguing with (the 99% of) Java programmers that code this way. They code this way, I shrug my shoulders and deal with it.
Actually, my experience is the opposite - they check like hell, all over the place, reflexively, because a null pointer exception is a blaring emergency that has to be fixed RIGHT NOW, so I always see Java code written like this: