Programming Confessions Thread
-
@Benjamin-Hall As long as you're consistent in your arrow directions, anyone looking at it can figure it out unless they are the most pedantic assholes playing dumb. So yeah, you need to remember which way they go.
-
I just wrote a generic utility method in Java that takes a Supplier as it's only parameter, performs a get on that and returns the value. This is surrounded with a try/catch for NPE, and if one is thrown, it is caught and null is returned.
This makes it possible to do a long call chain without any null checks and get the result or null if any of the objects in the chain is null. So, sort of a poor man's ?. but it's making me feel dirty.
-
@Carnage Not worth doing for performance reasons (afaik, it allocates the exception object before it enters the try block). But if written without golfing, might help finding where and how often it fails
-
@Carnage said in Programming Confessions Thread:
I just wrote a generic utility method in Java that takes a Supplier as it's only parameter, performs a get on that and returns the value. This is surrounded with a try/catch for NPE, and if one is thrown, it is caught and null is returned.
This makes it possible to do a long call chain without any null checks and get the result or null if any of the objects in the chain is null. So, sort of a poor man's ?. but it's making me feel dirty.fucking fuctional programmers. at least you feel dirty*.
*Someone, who will not be named but is devilishly handsome and name definitely isn't like CatsA, did this once too and had no fucks to give.
-
@Carnage said in Programming Confessions Thread:
So, sort of a poor man's ?. but it's making me feel dirty.
It's cleaner with
Optional
.
-
@dkf said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
So, sort of a poor man's ?. but it's making me feel dirty.
It's cleaner with
Optional
.Not trendy enough. Maybe a
Mono
and then he can be reactive!
-
@DogsB Does Java have any endofunctors? I feel like this will be important to know
-
@hungrier said in Programming Confessions Thread:
@DogsB Does Java have any endofunctors? I feel like this will be important to know
No.
-
@Applied-Mediocrity said in Programming Confessions Thread:
@Carnage Not worth doing for performance reasons (afaik, it allocates the exception object before it enters the try block). But if written without golfing, might help finding where and how often it fails
I measured the performance, and it's not that much worse that it matters outside of tight loops.
-
@dkf said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
So, sort of a poor man's ?. but it's making me feel dirty.
It's cleaner with
Optional
.Well, then I may just add well do the humongous if that checks each step. Optionals mainly just add compiler reminders to check if the value really is there, it doesn't make absence of sites any less stupid btobwork with.
-
@Benjamin-Hall said in Programming Confessions Thread:
I must confess--I can never remember which way the @#$#@$#@ arrows in a dependency graph go.
I can never remember which way the composition/aggregation "arrows" in UML class diagrams go. I scored negative points on several job interviews because of it.
-
@Carnage said in Programming Confessions Thread:
Optionals mainly just add compiler reminders to check if the value really is there, it doesn't make absence of sites any less stupid btobwork with.
A proper optional type with
map
method does make it less painful, and basically obsoletes your contraption.Also. Why exactly are you catching NPE instead of simply checking for null?
-
@Gąska I think the idea is to avoid "polluting" the code with multiple null checks on various things along the way, by substituting with a single try {} catch{} instead.
-
@Zecc oh okay. That makes more sense. Also makes me absolutely hate it.
-
I've re-read @Carnage's post, and if the result is one single long chain, I'm not even mad. It's likely more readable than multiple statements with a bunch of temporary variables and null-checks interspersed .
I haven't touched Java for a long time. Definitely before it got lambdas. How difficult is it to write a static generic method taking a bunch of lambdas where each one is run with the result of the previous call?
Eg, convert this:
try { return obj. doThis(). thenThis(). andThis(). finishIt(); } catch(NullPointerException _){ return null; }
to this:
return DoUntilNull( obj, o => o.doThis(), o => o.thenThis(), o => o.andThis(), o => o.finishIt() );
-
@Gąska said in Programming Confessions Thread:
@Zecc oh okay. That makes more sense. Also makes me absolutely hate it.
Yeah, it's not pretty, and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
Normally I don't really care, but when the call chains start being 10+ deep it's gets really painful. And yeah that is also a retarders data structure so that's also wrong.
-
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
-
@Zecc said in Programming Confessions Thread:
I've re-read @Carnage's post, and if the result is one single long chain, I'm not even mad. It's likely more readable than multiple statements with a bunch of temporary variables and null-checks interspersed .
I haven't touched Java for a long time. Definitely before it got lambdas. How difficult is it to write a static generic method taking a bunch of lambdas where each one is run with the result of the previous call?
Eg, convert this:
try { return obj. doThis(). thenThis(). andThis(). finishIt(); } catch(NullPointerException _){ return null; }
to this:
DoUntilNull( obj, o => o.doThis(), o => o.thenThis() o => o.andThis() o => o.finishIt() );
That is pretty much trivial, I could write such a util class as well for doing a long call chain null safely. But it's still really ugly compared to thing?.stuff?.doodad?.gadget?.interesting Bit
-
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
They are still shit and boilerplaty, and doesn't grant conciseness of code compared to proper language features.
-
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
They are still shit
Much less shit than your solution. For example, it doesn't swallow unexpected NPEs that happen deeper in code.
and boilerplaty
Only a little. And you can chain it just fine. And it looks the same as your list manipulation code (if you use map/filter/etc. for lists).
and doesn't grant conciseness of code compared to proper language features.
But it does grant more features, such as
orElse
andfilter
methods. There's a reason why every language in existence is switching to this style.
-
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
They are still shit
Much less shit than your solution. For example, it doesn't swallow unexpected NPEs that happen deeper in code.
Not really.
and boilerplaty
Only a little. And you can chain it just fine. And it looks the same as your list manipulation code (if you use map/filter/etc. for lists).
Yeah, everywhere. It's ugly. Java is not lacking boilerplate.
and doesn't grant conciseness of code compared to proper language features.
But it does grant more features, such as
orElse
andfilter
methods. There's a reason why every language in existence is switching to this style.orElse is granted by ?: In combination with ?. way more succinctly. Filter seems like collection manipulation, and should probably live there, but yeah. That the majority is doing something is not really any argument either. Programming had a long and dishonored past of cargo culting the wrong things.
Also, fixing missing language features with libraries adds the fun problem that if something you use doesn't use to library, you are fucked.
-
@Gąska said in Programming Confessions Thread:
But it does grant more features, such as
orElse
aka
??
and
filter
methods.There's a reason why every language in existence is switching to this style.
Agreed.
-
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
They are still shit
Much less shit than your solution. For example, it doesn't swallow unexpected NPEs that happen deeper in code.
Not really.
Not really as in you have a way to separate deep NPEs from top-level NPEs, or not really as in your code is flawless and bug-free and there's no way for a stray NPE to get in there?
and boilerplaty
Only a little. And you can chain it just fine. And it looks the same as your list manipulation code (if you use map/filter/etc. for lists).
Yeah, everywhere. It's ugly. Java is not lacking boilerplate.
Wait wait wait. Are you really saying the map/filter/etc. style of list manipulation is ugly? Like, what would you use instead that looks better and has less boilerplate? I can understand your argument for optionals, but for lists it just doesn't make sense.
Programming had a long and dishonored past of cargo culting the wrong things.
It also has a long past of refusing to use standard solutions to common problems and instead reinventing square wheels over and over again. And you seem set on continuing that tradition.
Also, fixing missing language features with libraries adds the fun problem that if something you use doesn't use to library, you are fucked.
You have the exact same problem when something you use doesn't use the language feature. Jeez, it's not like it's an external dependency, it's part of the standard library, available everywhere you have Java 8 and up.
-
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
They are still shit
Much less shit than your solution. For example, it doesn't swallow unexpected NPEs that happen deeper in code.
Not really.
Not really as in you have a way to separate deep NPEs from top-level NPEs, or not really as in your code is flawless and bug-free and there's no way for a stray NPE to get in there?
Not really as in it is a huge data structure without logic, if something is null, it's right there in the call chain.
and boilerplaty
Only a little. And you can chain it just fine. And it looks the same as your list manipulation code (if you use map/filter/etc. for lists).
Yeah, everywhere. It's ugly. Java is not lacking boilerplate.
Wait wait wait. Are you really saying the map/filter/etc. style of list manipulation is ugly? Like, what would you use instead that looks better and has less boilerplate? I can understand your argument for optionals, but for lists it just doesn't make sense.
No, I was taking about optional. I like the streams stuff.
Programming had a long and dishonored past of cargo culting the wrong things.
It also has a long past of refusing to use standard solutions to common problems and instead reinventing square wheels over and over again. And you seem set on continuing that tradition.
Feel free to think whatever you like. You were the guy that jumped to conclusions and did not even bother to ask about the use.
I also posted about it in this very thread.Also, fixing missing language features with libraries adds the fun problem that if something you use doesn't use to library, you are fucked.
You have the exact same problem when something you use doesn't use the language feature. Jeez, it's not like it's an external dependency, it's part of the standard library, available everywhere you have Java 8 and up.
No, I don't. See the examples I've posted of null coalescing for instance with regard to optionals vs language features. Another example is the builder pattern vs named parameters.
-
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
and Java really should add a nice way to deal with it instead of all the retarded boilerplatey workarounds for a missing language feature.
They are still shit
Much less shit than your solution. For example, it doesn't swallow unexpected NPEs that happen deeper in code.
Not really.
Not really as in you have a way to separate deep NPEs from top-level NPEs, or not really as in your code is flawless and bug-free and there's no way for a stray NPE to get in there?
Not really as in it is a huge data structure without logic, if something is null, it's right there in the call chain.
Are you alone on the project? Then fair enough. Are there other devs too who may see your helper class and use it themselves elsewhere? Then check back in a year.
Also, fixing missing language features with libraries adds the fun problem that if something you use doesn't use to library, you are fucked.
You have the exact same problem when something you use doesn't use the language feature. Jeez, it's not like it's an external dependency, it's part of the standard library, available everywhere you have Java 8 and up.
No, I don't. See the examples I've posted of null coalescing for instance with regard to optionals vs language features. Another example is the builder pattern vs named parameters.
Before I deride you for mixing up conversation lines. Are you still talking about "the fun problem if something you use doesn't use to library" here? Because no such problem exists. Interoperability with code that doesn't use Optional at all isn't a problem because
Optional.ofNullable
can convert any possibly-null value into an Optional. Yes it's a tiny bit of boilerplate (but you only have to do it once per call chain), and yes?.
would be much shorter, but no actual problem in the form of "this is impossible to do without a whole lot of dumb boilerplate conversion code" exists.
-
@Zecc said in Programming Confessions Thread:
I've re-read @Carnage's post, and if the result is one single long chain, I'm not even mad. It's likely more readable than multiple statements with a bunch of temporary variables and null-checks interspersed .
I haven't touched Java for a long time. Definitely before it got lambdas. How difficult is it to write a static generic method taking a bunch of lambdas where each one is run with the result of the previous call?
Eg, convert this:
try { return obj. doThis(). thenThis(). andThis(). finishIt(); } catch(NullPointerException _){ return null; }
to this:
return DoUntilNull( obj, o => o.doThis(), o => o.thenThis(), o => o.andThis(), o => o.finishIt() );
You mean something like this?
return Optional.ofNullable(obj) .map(Foo::doThis) .map(Foo::thenThis) .map(Foo::andThis) .map(Foo::finishIt) .orElse(null);
-
@dkf Some of those
map
calls might instead need to beflatMap
calls. It really depends on whether they returnOptional
s or not.
-
@DogsB said in Programming Confessions Thread:
@Carnage said in Programming Confessions Thread:
I just wrote a generic utility method in Java that takes a Supplier as it's only parameter, performs a get on that and returns the value. This is surrounded with a try/catch for NPE, and if one is thrown, it is caught and null is returned.
This makes it possible to do a long call chain without any null checks and get the result or null if any of the objects in the chain is null. So, sort of a poor man's ?. but it's making me feel dirty.fucking fuctional programmers. at least you feel dirty*.
*Someone, who will not be named but is devilishly handsome and name definitely isn't like CatsA, did this once too and had no fucks to give.
Ooh! Ooh! Can I be SnakesV?
-
This is 2021. You can be whatever you want to be, you don't need permission.
-
@Zerosquare said in Programming Confessions Thread:
This is 2021. You can be whatever you want to be, you don't need permission.
OK so my pronouns are:
ssseee, ssser, sssits
ETA: What other languages can express what the sound of a snake?
In my head its:
sss slurpple
And I know that's not accurate.
Since the "sss" is much longer than the in-between sound.
I'd like some constructive feedback, so I commit to my pronouns.
-
@Karla said in Programming Confessions Thread:
I'd like some constructive feedback, so I commit to my pronouns.
ssSss, SSss, SSSS?
-
@dcon said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
I'd like some constructive feedback, so I commit to my pronouns.
ssSss, SSss, SSSS?
Not sure if that is helpful. Or that my employer may
exceptaccept.
-
@Karla said in Programming Confessions Thread:
I'd like some constructive feedback, so I commit to my pronouns.
If you're a rattle snake, maybe you could use some
q
s to represent the rattle.
-
@boomzilla said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
I'd like some constructive feedback, so I commit to my pronouns.
If you're a rattle snake, maybe you could use some
q
s to represent the rattle.I like the idea of using some
q
s but I'm not really sure that it universally understood.
-
@Karla said in Programming Confessions Thread:
@boomzilla said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
I'd like some constructive feedback, so I commit to my pronouns.
If you're a rattle snake, maybe you could use some
q
s to represent the rattle.I like the idea of using some
q
s but I'm not really sure that it universally understood.As opposed to how everyone understands and enthusiastically supports neopronouns?
-
@boomzilla said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
@boomzilla said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
I'd like some constructive feedback, so I commit to my pronouns.
If you're a rattle snake, maybe you could use some
q
s to represent the rattle.I like the idea of using some
q
s but I'm not really sure that it universally understood.As opposed to how everyone understands and enthusiastically supports neopronouns?
But I work for the City of New York, who's mayor declared that there are 32 genders (and as such, must be 32 sets of pronouns).
DeBlasio card beats Trump card in NYC.
-
@Karla said in Programming Confessions Thread:
there are 32 genders
That's convenient. We can encode any possible gender expression with just four bytes!
-
@Gąska said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
there are 32 genders
That's convenient. We can encode any possible gender expression with just four bytes!
Still a bit of a downgrade from using a bit.
-
@Carnage said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Karla said in Programming Confessions Thread:
there are 32 genders
That's convenient. We can encode any possible gender expression with just four bytes!
Still a bit of a downgrade from using a bit.
Until Y2G when it's to become a freeform text field (and you bet I can identify as NULL, too)
-
Status: Seriously considering simply rebooting the Arduino when free heap goes too low instead of finding whatever the fuck is causing it to fragment ever-so-slowly...
-
@Tsaukpaetra said in Programming Confessions Thread:
whatever the fuck is causing it to fragment
TsHDF
-
@Tsaukpaetra: this is an embedded system. You should not be doing any dynamic memory allocation in the first place.
-
@Zerosquare said in Programming Confessions Thread:
You should not be doing any dynamic memory allocation in the first place.
Correct. Which is why I'm somewhat confused. And also why I'm loathe to try figuring out what to blame, because as far as I know all my strings are allocated once and up front, and shouldn't be fucked around with afterward.
I'm assuming something something copy blargh, but enough effort has been put into this thing that rebooting every 12 hours won't negatively impact a fucking temperature probe sufficiently. Especially since the sample rate is 12/hr.
-
@Tsaukpaetra any chance of running the code through Valgrind?
-
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra any chance of running the code through Valgrind?
It's Arduino, I wouldn't know the first step to even attempting it...
-
@Tsaukpaetra I didn't mean on-board. That would be pretty much impossible given the hardware constraints. But I know nothing about Arduino stack, which gives me hope it could be somehow compiled as a regular Linux program or at least run in debuggable emulator.
Alternatively, hook up a custom allocator that logs the allocations.
-
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra I didn't mean on-board. That would be pretty much impossible given the hardware constraints. But I know nothing about Arduino stack, which gives me hope it could be somehoe compiled as a regular Linux program or at least run in debbuggable emulator.
Alternatively, hook up a custom allocator that logs the allocations.
All of that is wwwaaaaayyyyyyyyyy too much effort.
It's not like my temperature probe is going to space where a reboot twice a day brings heavy concern...
-
@Tsaukpaetra said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra I didn't mean on-board. That would be pretty much impossible given the hardware constraints. But I know nothing about Arduino stack, which gives me hope it could be somehoe compiled as a regular Linux program or at least run in debbuggable emulator.
Alternatively, hook up a custom allocator that logs the allocations.
All of that is wwwaaaaayyyyyyyyyy too much effort.
Says the guy who spent countless days making Windows 10 run with 1GB RAM.
-
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra said in Programming Confessions Thread:
@Gąska said in Programming Confessions Thread:
@Tsaukpaetra I didn't mean on-board. That would be pretty much impossible given the hardware constraints. But I know nothing about Arduino stack, which gives me hope it could be somehoe compiled as a regular Linux program or at least run in debbuggable emulator.
Alternatively, hook up a custom allocator that logs the allocations.
All of that is wwwaaaaayyyyyyyyyy too much effort.
Says the guy who spent countless days making Windows 10 run with 1GB RAM.
That's more fun and has immediate visibility and (arguably) more utility.
-
@Tsaukpaetra I'd argue the other way on all three counts. But you do you.