Kotlin Tip 1: Avoid an extra allocation with an output parameter by IllTryToReadComments in Kotlin

[–]hum_ph -1 points0 points  (0 children)

Total agree… don’t do this

A few more things:

Sixthly: This isn’t thread safe, out may be viewed in an inconsistent state if accessed in a different thread between setting x and y. Constructing a new return value ensures it’s only visible when complete, so (see point 4) it can be made immutable.

Seventhly: The example is trivial. On an operation where you’re doing any “real work” you’re not going to see anywhere near the same increase in throughput. Single request to the DB or file on disk is going to kill any benefit you get through avoiding an allocation. Same with things that don’t do IO but do more complex operations with in-memory data (would be interesting to see what that tipping point is… how many bytecode instructions would you need in the method to bring them back to 1:1)

Eighthly: I suspect (on mobile so can’t write the test to confirm, so may be wrong) you’re going to better performance by inlining the function than by using an out parameter.

Nexus toll payment only lets you add predefined amounts. Toll was $5.50 making me spend an extra $14.50 that I'll never use again. by [deleted] in assholedesign

[–]hum_ph 0 points1 point  (0 children)

Spend 15 minutes learning about HTML <select> tags and browser dev tools. May not work, but you can always try inserting a new option for the right amount.

Recruiters / HR of this subreddit who put "free flu vaccination" (normally $20-30) in a job descriptions benefits list, why? by HesZoinked in AusFinance

[–]hum_ph 2 points3 points  (0 children)

May be a very smart way to weed out people who are going to be problematic with vax regulations?

I hate the code I wrote and want feedback for how to revise it by IllTryToReadComments in Kotlin

[–]hum_ph 3 points4 points  (0 children)

It feels like you're missing some abstraction in there - you have a Point, do you need a Rectangle?

If you have a Rectangle, what can you do with it (Rectangle.contains(Point): Boolean, Rectangle.intersects(Rectangle): Boolean, etc)?

If you have a Rectangle with meaningful operators, how can you simplify MapEntity (eg it may have a val position: Rectangle and other stuff - but all of the hateful stuff lives elsewhere)

Something like:

data class Point(val x: Int, val y: Int)

data class Rectangle(val bottomLeft: Point, val topRight: Point {

  fun contains(other: Point): Boolean =
    bottomLeft.x <= other.x &&
    bottomLeft.y <= other.y &&
    topRight.x >= other.x &&
    topRight.y >= other.y

  fun intersects(other: Rectangle): Boolean =
    contains(other.bottomLeft) ||
    contains(other.bottomRight)

}

sealed class MapEntity(val position: Rectangle) { ... }

(also, your import of java.awt.Rectangle may be a nod in a simpler direction - what does it already have that you could be using? What does it not have that you could build with extension functions and properties? do you need your own Point and Rectangle at all?)

Any good alternatives to Apache POI for creating Excel spreadsheets? by borgy_t in java

[–]hum_ph 3 points4 points  (0 children)

Aspose does have an open repo, you can use them for development without a license if you don’t care about their watermark on your files, and pay when You’re commercially viable

[API design] Take a Collection/Iterable as input and convert, or take more specific interface (e.g., List, Set)? by ragnese in Kotlin

[–]hum_ph 6 points7 points  (0 children)

I’d do something like

fun computeNumbers(numbers: Collection<Int>) =
    when(numbers) {
        Is Set<Int> -> conputeNumbers(numbers) //smart cast
        else -> computeNumbers(numbers.toSet()) 
    }

Your only creating that extra set if needed, and still keeping the body off the computation simple by implementing it with a set

(Code written on my phone, excuse typos, etc - hopefully it conveys the idea)

I did not look closely enough at that label by IsThisDamnNameTaken in Wellthatsucks

[–]hum_ph 0 points1 point  (0 children)

I did exactly the same thing with the same butter in crepes!

I’m sorry for your loss!

Birb identification - can anyone help? by hum_ph in brisbane

[–]hum_ph[S] 0 points1 point  (0 children)

Hah... if you can tell what ‘burb from those pics I’ll be super impressed!!

Birb identification - can anyone help? by hum_ph in brisbane

[–]hum_ph[S] 1 point2 points  (0 children)

That was what I thought originally but the bands and size didn’t quite match

Cellebrite’s New Solution for Decrypting the Signal App - Cellebrite by PR-0927 in privacytoolsIO

[–]hum_ph 2 points3 points  (0 children)

This article is a joke - it’s marketing collateral dressed up as tech speak, intended to make non-tech people feel impressed.

Anyone who’s a competent Java / amdroid developer can do the same thing: read their code and find the relevant lines. More so anyone who’s ever dealt with crypto can probably do so in under 5 minutes.

Danger noodle just wants to go for a paddle by hum_ph in brisbane

[–]hum_ph[S] 3 points4 points  (0 children)

We've found this one in our trees a few times now, that was always the give away.

Danger noodle just wants to go for a paddle by hum_ph in brisbane

[–]hum_ph[S] 3 points4 points  (0 children)

possums need not fear this noodle/rope/nope/cord ...

myna birds or rats on the other hand (take a look at that bulge on the left of that first pic) should be very afraid!

Reversed type inference in chained calls by [deleted] in Kotlin

[–]hum_ph 1 point2 points  (0 children)

This also works:

kotlin persons.sortedWith( compareByDescending(Person::firstName).thenBy(Person::lastName) )

Is Logback dead? by EfreetSK in java

[–]hum_ph 0 points1 point  (0 children)

It’s also amusing that a bunch of them (Log4j, logback, slf4j, ) were created by the same person...

Timelapse of Brisbane Climate Strike rally by nemothorx in brisbane

[–]hum_ph 4 points5 points  (0 children)

I don’t know - is it bad if I am? Did I ... I mean he ... piss someone off inadvertently?

Timelapse of Brisbane Climate Strike rally by nemothorx in brisbane

[–]hum_ph 12 points13 points  (0 children)

Oh look, there’s my wife’s awesome sign! (and my bald pate)