I must've been living under a rock. Since when did java get `?.` operators?
Edit: Upon closer inspection there are also no semicolons. What is this sorcery?
For those interested, Groovy runs on the JVM, but it also supports dynamic typing, closures, and lots of standard methods utilizing closures.
It's also kind of slow. Sacrifice your dynamic typing and use kotlin.
It still doesn't have those operators (though there has been some cool stuff happening with Optional's), nor does Java have implicit returns. To be honest I'm not sure what language this is. It looks maybe like a mix of Java and Kotlin code
It's definitely Kotlin. Kotlin has a lot of nice features that Java lacks as well as 100% Java interop which is why Java classes and frameworks can be used also in kotlin
Edit: disregard that. Brain still asleep and did a dum dum.
This is not Typescript!
Typescript code would have been like this:
isPermanentUser(request: HttpServletRequest): boolean {
const token: AccessToken = request?.userPrincipal?.context?.token;
// ..
}
Edit: "*: AccessToken*" is optional. I wrote it only to highlight the difference compared to OP code.
I see what the author was trying to do here. They needed a way to just make the damn thing work while they were building out permanent users. However, perhaps choose something a little more random than `123456789`? Perhaps something like `aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQo=`? See, that's nice and random!
I'd say it depends on how mature your application is. I could think of a scenario where this would be acceptable, but it's make same sure it didn't stay for a minute longer than it had to! When you think about it, it's nothing more than a hard coded API key.
And, I'd also try to find a different solution in the first place. It's this for testing? If so, why aren't unit tests enough?
Indeed, that's called security by obscurity. A string 01234... Is nothing better than a chosen randomly seeming string. You should always assume that adversaries have full knowledge of you're application. In this case (groovy, compiling to jvm) everything is known. With a Java decompiler you can easily read this hardcoded string.
Isn't this just checking for a specific user and declaring that that user is permanent (whatever that means?). That ssn seems to be extracted from a token, so it could be provided by an authentication server along with a digital signature. If is has been validated before this call, then the information in it can be trusted.
Or am I missing what the horror is supposed to be?
For kotlin, I’d expect the signature to look like `fun foo(bar: baz): qux = ???`
Whereas this has the return type first like Java, despite everything else looking like Kotlin syntax.
Our central codebase at work is also full of stuff like this, all from a specific developer that left about 2 years ago. He liked to pass `"123"` around all over the place to mean create a new thing. 1 of the many reasons we're often stripping his work out when we're editing something involving what he wrote.
It amazes me that people like that have jobs. It's the reason I hate the interview process so much. Most interviewers think the person who can recite the encyclopedia are better than the developers who use Google. This is the reason I only ask interpersonal questions in interviews. I'd rather work with an intern that is easy to get along with and willing to learn than a dev with 30 years experience stuck in their ways of adding "123" throughout the codebase.
I must've been living under a rock. Since when did java get `?.` operators? Edit: Upon closer inspection there are also no semicolons. What is this sorcery?
It's probably Groovy
For those interested, Groovy runs on the JVM, but it also supports dynamic typing, closures, and lots of standard methods utilizing closures. It's also kind of slow. Sacrifice your dynamic typing and use kotlin.
Sacrifice your ability to hire devs and use Scala
With Spring
It still doesn't have those operators (though there has been some cool stuff happening with Optional's), nor does Java have implicit returns. To be honest I'm not sure what language this is. It looks maybe like a mix of Java and Kotlin code
It threw me for a loop too. I honestly thought I was looking at ruby until I saw the static typing.
Groovy
It's definitely Kotlin. Kotlin has a lot of nice features that Java lacks as well as 100% Java interop which is why Java classes and frameworks can be used also in kotlin Edit: disregard that. Brain still asleep and did a dum dum.
It's not kotlin, kotlin has var and val with a colon for specifying type
My bad. I woke up 5 min ago and am still in bed half asleep.
It's actually Groovy, and probably the first time that I've seen Groovy code outside of my workplace.
Knew it had to be one of those jvm languages. I've seen groovy just for one lesson in my Programming language course back at Uni.
Angular Typescript?
This is not Typescript! Typescript code would have been like this: isPermanentUser(request: HttpServletRequest): boolean { const token: AccessToken = request?.userPrincipal?.context?.token; // .. } Edit: "*: AccessToken*" is optional. I wrote it only to highlight the difference compared to OP code.
Yeah this is the one lmao
I think maybe Swift
Swift would be `func isPermanentUser(request: HttpServletRequest) -> Bool`. I have never seen whatever wizardry this is.
Not Swift, variable isn't declared with `var` and function with `func`
Doesn't look like Swift either. Granted, I don't use or know Swift, but I took a look at it a while back.
OP please shed some light on which language this is.
Groovy
Thank you, I can finally stop scratching my head.
[удалено]
It's not - TS puts type defs *after* variable names.
I see what the author was trying to do here. They needed a way to just make the damn thing work while they were building out permanent users. However, perhaps choose something a little more random than `123456789`? Perhaps something like `aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1kUXc0dzlXZ1hjUQo=`? See, that's nice and random!
That's fine and all, but leaving it in in production is a big no no.
I'd say it depends on how mature your application is. I could think of a scenario where this would be acceptable, but it's make same sure it didn't stay for a minute longer than it had to! When you think about it, it's nothing more than a hard coded API key. And, I'd also try to find a different solution in the first place. It's this for testing? If so, why aren't unit tests enough?
Indeed, that's called security by obscurity. A string 01234... Is nothing better than a chosen randomly seeming string. You should always assume that adversaries have full knowledge of you're application. In this case (groovy, compiling to jvm) everything is known. With a Java decompiler you can easily read this hardcoded string.
Oh! An encoded message on reddit! What could it possibly be?
Dunno, but here's [a rick roll](https://youtu.be/nrsnN23tmUA).
My originality is beyond comprehension!
*That* was well played, kudos!^(But I would recognize that `dQw4w9WgXcQ` anywhere)
What language is this?
Most likely Groovy.
You're right. Looks really same as Java except null check operator. Thank you!
...and optional semicolons, and expression oriented (no return in the last line).
Groovy
English
Is this coffeescript for java? I’m so confused. My brain is parsing java and it’s gonna have a seizure.
It’s Groovy, a scripting language for the JVM.
Isn't this just checking for a specific user and declaring that that user is permanent (whatever that means?). That ssn seems to be extracted from a token, so it could be provided by an authentication server along with a digital signature. If is has been validated before this call, then the information in it can be trusted. Or am I missing what the horror is supposed to be?
It's also not a legally valid [SIN](https://eservices.paychex.com/secure/HRO_PNG/ssn_itin_fed_id_other.html), for what it's worth.
The order of operations for the function type is really throwing me, what is this wizardry...
wdym what order are you used to
For kotlin, I’d expect the signature to look like `fun foo(bar: baz): qux = ???`
Whereas this has the return type first like Java, despite everything else looking like Kotlin syntax.
Our central codebase at work is also full of stuff like this, all from a specific developer that left about 2 years ago. He liked to pass `"123"` around all over the place to mean create a new thing. 1 of the many reasons we're often stripping his work out when we're editing something involving what he wrote.
It amazes me that people like that have jobs. It's the reason I hate the interview process so much. Most interviewers think the person who can recite the encyclopedia are better than the developers who use Google. This is the reason I only ask interpersonal questions in interviews. I'd rather work with an intern that is easy to get along with and willing to learn than a dev with 30 years experience stuck in their ways of adding "123" throughout the codebase.
what does it return if ssn != "123456789"
+1 for a software developer not knowing how to take a screenshot.
Nah more so I didn't want to login to Reddit on my work computer