ProgrammerHumor

checkOutMyCode

checkOutMyCode
https://i.redd.it/vch87332zqdf1.jpeg
Reddit

Discussion

InsideBSI
:c::cp::cs::js::ts::py:

java code that looks like python yeah, nice

12 hours ago
legendLC

Must add this comment:

// Do not reformat the braces {}. It breaks the production.

6 hours ago
RiceBroad4552
:s:

"Java" code (or actually JVM code) that looks like Python would be more this here:

object Permuter:
   private def permute(n: Int, a: Array[Char]) =
      if n == 0 then
         println(String.valueOf(a))
      else
         for i <- Range(0, n+1) do
            permute(n-1, a)
            swap(a, if n % 2 == 0 then i else 0, n)
   private def swap(a: Array[Char], i: Int, j: Int) =
      val saved = a(i)
      a(i) = a(j)
      a(j) = saved

That's Scala, a kind of Python + Haskell for the JVM.

This code wouldn't be useful of course for obvious reasons: The static methods (methods on an object in Scala) are private, so you can't call them from the outside…

Also the Range(0, n+1) expression isn't idiomatic Scala. You would usually use the 0 to n syntax sugar instead. But the Range looks more like Python so I've written it like that.

Beside that, that's anyway not idiomatic Scala as it uses mutable values and imperative loops. Also Array is just the "naked" Java Array, and not a Scala collection, and one does usually not use Array directly. Actually also not in Java!

Writing that above code makes also no sense in general as Scala comes with a permutations method on collections (and Array through extension methods).

But syntactical the code above is pretty close to Python, imho.

16 minutes ago
DigitalJedi850
:cs:

I hate that my brain made me sort out what this does…

12 hours ago
jungle

Funny how all (or most) comments are about the formatting and not the horrific implementation of permute. I can't even figure out if it works.

8 hours ago
suskio4
:c::cp::py::asm::lua:

This is why its so good at permuting

8 hours ago
SinsOfTheAether

It's the permuta triangle algorithm

2 hours ago
Anaxamander57
:py::rust:

Depression is iteratively calling a recursive algorithm inside of itself.

2 hours ago
rruusu

It does nothing, as that class only has two methods and both are private. (The closing brace for the class is at the end of the last line.)

Whatever its permute method would do, if anyone were allowed to call it, it would have a time and console output complexity of O((n+1)!) (factorial time), unless n > a.length - 1, in which case it'll throw an ArrayIndexOutOfBoundsException.

Edit: Off by one in the time complexity.

6 hours ago
SovereignPhobia

Doesn't it also just not have a termination case? The case presented is a print and not a return.

39 minutes ago
hawkwolfe

I’m responding after your edit and if it was to edit your time complexity to add the “+1”, that’s unnecessary. Big O notation is concerned with the asymptotic growth of the function relative to n, and as n approaches infinity the difference in the function output due to any constant factor approaches 0.

37 minutes ago
sammy-taylor
:js::elixir-vertical_4::cp:

I was like “what friggin language is this” until I saw the horrifying brackets 🤢

11 hours ago
Ahazveroz

Jathon? Pyva?

12 hours ago
NobodyPrime8

is this the "Jason" every web developer seems to be so obsessed over?

11 hours ago
ohmywtff

Jython probably, since there's the cython

8 hours ago
RiceBroad4552
:s:

Jython is already taken…

https://www.jython.org/

13 minutes ago
anotherbutterflyacc

I was like “is this python…? I’m so confused” and then saw the brackets and physically startled lol

11 hours ago
Boris-Lip

IRL depression doesn't really look like anything, though

11 hours ago
TooSoonForThePelle

True. I should post a selfie.

11 hours ago
giantrhino

I was so confused until I finally looked in the right margin.

Kill it. Kill it with fire.

10 hours ago
SPAMTON____G_SPAMTON
:unity:

This isn't depression. This is heresy.

11 hours ago
ghstber

Brother, get the flamer... the heavy flamer. 

10 hours ago
spac1al

kris…this code is not a [BIG SHOT]

34 minutes ago
giantrhino

Tfw you find out you’re gonna have to put your friend down.

10 hours ago
Deep__sip
:js::j::c:

This is autism

11 hours ago
EldritchEne

I- really can't tell if I love or hate this

11 hours ago
ZunoJ
:cs: :asm: :c:

Aside from the obvious, why are the methods static and not extension methods? Or just injected as a singleton?

9 hours ago
SKabanov

Everything in JVM-based languages needs to be encased within a class, even if you just need to define a collection of pure functions. Kotlin allows you to create "classless" files in which you define these pure functions, but that's ultimately syntactic sugar.

1 hour ago
ZunoJ
:cs: :asm: :c:

Sure but static functions like this are an anti pattern. It bypasses DI and makes the code less testable

1 hour ago
SKabanov

Pure static functions are not per se an anti-pattern, and forcing everything into classes for the sake of DI and testability can be just as much of an anti-pattern itself. That being said, I'll admit that I misread the class and that the actual issue is that the functions aren't pure: it's got a stealth dependency of a PrintStream instance where it's printing out the permutation result. The class should be rewritten to include a PrintStream member field that gets used in the System.out.println() call, and the functions would then become instance functions instead of static - there's the DI that you'd want.

41 minutes ago
RiceBroad4552
:s:

Because Java still doesn't have extension methods…

The singleton code would be awful complex, especially if it needs to be thread safe.

6 minutes ago
SuitableDragonfly
:cp:py:clj:g:

No, I think that's the manic stage.

10 hours ago
Corelianer

We write code in a readable form for humans not machines.

10 hours ago
AStripe

So nobody remembers c++?

8 hours ago
IceColdFresh

Variable width font coders BTFO

11 hours ago
RiceBroad4552
:s:

I'm not sure what you mean.

The chars align perfectly in columns, so this isn't a variable with font used for that code.

8 minutes ago
baltimooree

The RHS is killing me bro 😶

10 hours ago
drsimonz
:py::cp::cs::re::ts:

Anything other than 1TBS is mental illness, change my mind.

10 hours ago
RiceBroad4552
:s:

What's "1TBS"?

4 minutes ago
Sad_Welcome3776

LOL the code segment is the most accurate depiction of how my brain feels on a daily basis 😂 #ProgrammerLife

9 hours ago
Etheo
:bash::py::table_flip::redditplatinum:

Hi police? I'd like to report an assault.

ON MY EYES

9 hours ago
Debopam77

This isn't depression, it's a cry for help.

9 hours ago
RiceBroad4552
:s:

Indeed! At the moment someone makes you use some language that requires useless syntax noise like braces and semicolons one starts to cry for help, that's true.

2 minutes ago
Select_Blackberry543

Yep, that make my readability drop to -1

9 hours ago
Elijah629YT-Real
:ts::js::c::cp::cs::rust:

It’s not even good code

9 hours ago
WinkAndWithdrawn

Lmao, both are accurate, but that Java code hits a bit too close to home! Anyone else debugging till 3 AM feeling like a part of their soul is being permuted? 😅

8 hours ago
Ineeddramainmylife13

Ugh reminds me of the time I accidentally took the harder coding class that was required. One of the worst classes ever (teacher sucked)

8 hours ago
sakkara

When a python dev tries have for the first time :D

7 hours ago
korneev123123
:py:

Most of my programming experience is python, so I never understood what is wrong until comment section. My only guess was "Java surely must have built-in function for that, like itertools.permutations in python. Maybe it's the joke, that depressed person rewrites library functions"

3 hours ago
milboldi

I had my C++ segfault in the inplementation of GTest on a random ass move. We debugged it for 3 days, than we came to the conclusion, that my linux distro is fucked, and the problem isn't in the code.

3 hours ago
P-h-a-n-t-a

Took me a while to see wtf

1 hour ago
ginopono
:py: :r: :powershell:

My instant reaction was that it should be "check out" until I considered that they may have meant checkout

1 hour ago
AibofobicRacecar6996

That's not depression, that's insanity

11 minutes ago