Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
pseudorandom name
May 6, 2007

more like dICK posted:

in java you just extend the compiler using undocumented internal interfaces to make it a different programming language

Adbot
ADBOT LOVES YOU

CPColin
Sep 9, 2003

Big ol' smile.

Max Facetime posted:

or just check for nulls in a less stupid way:

return computer != null && computer.getSoundcard() != null && computer.getSoundcard().getUSB() != null
? computer.getSoundcard().getUSB().getVersion() : "UNKNOWN";

god that article makes me so angry

Eclipse will still flag a bunch of this stuff as "potential" null pointer accesses, because who can say that the second or third call to getSoundcard() won't suddenly return null!?

Also, Eclipse has no idea how to do null analysis on that Optional class. Basically, null analysis should be built into the drat language already.

Sapozhnik
Jan 2, 2005

Nap Ghost
that example article is loving terrible in all sorts of ways

also who gives a poo poo about getters/setters, you know you can just have your data member poo poo public and you're not going to get hanged by the Inquisition right

sometimes a struct is just a struct. other times validating data might be a good idea idk it seems to me like an object should always enforce its own validity so a setter would be a good place to perform validation.

c# properties are not that offensive but not a particularly good idea either imo. you inevitably get dipshits who do something not-thread-safe or mutating or not-idempotent in a c# getter. just like how they blindly c&p'ed java to make c# 1.0 and then bolted their own redundant poo poo on top like having both Equals() and an operator== overload and expressing one in terms of the other is a loving pain in the dick. does x == y test logical equality? identity??? who the gently caress knows???????

Alt-poo poo-S, R to bring up the autogenerate dialog, Alt-A to select everything, Enter, there, now you have a bunch of accessors. now stop being a loving baby. sometimes being clear about what's going on is worth a few extra (automated) keystrokes.

really all that this demonstrates is that, once again, stupid bad programmers try to use Java and then blame Java for their own lovely ineptitude, and that Java is the best programming language for most jobs performed by adults who perform useful labour. the existence of plangs to draw off insecure children who have something to prove is something i am thankful for every day.

more like dICK
Feb 15, 2010

This is inevitable.

ya it owns

brap
Aug 23, 2004

Grimey Drawer
java meets the needs of the enterprise

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

Mr Dog posted:

that example article is loving terrible in all sorts of ways

also who gives a poo poo about getters/setters, you know you can just have your data member poo poo public and you're not going to get hanged by the Inquisition right

sometimes a struct is just a struct. other times validating data might be a good idea idk it seems to me like an object should always enforce its own validity so a setter would be a good place to perform validation.

c# properties are not that offensive but not a particularly good idea either imo. you inevitably get dipshits who do something not-thread-safe or mutating or not-idempotent in a c# getter. just like how they blindly c&p'ed java to make c# 1.0 and then bolted their own redundant poo poo on top like having both Equals() and an operator== overload and expressing one in terms of the other is a loving pain in the dick. does x == y test logical equality? identity??? who the gently caress knows???????

Alt-poo poo-S, R to bring up the autogenerate dialog, Alt-A to select everything, Enter, there, now you have a bunch of accessors. now stop being a loving baby. sometimes being clear about what's going on is worth a few extra (automated) keystrokes.

really all that this demonstrates is that, once again, stupid bad programmers try to use Java and then blame Java for their own lovely ineptitude, and that Java is the best programming language for most jobs performed by adults who perform useful labour. the existence of plangs to draw off insecure children who have something to prove is something i am thankful for every day.

do you have a better way to use Optional

jony neuemonic
Nov 13, 2009

FamDav posted:

re: rails is slow as poo poo

here's a pointless framework comparison that shouldn't be expected to tell you much of anything besides rails being ridiculously, incredulously slow

https://www.techempower.com/benchmarks/#section=data-r9&hw=peak&test=fortune

still faster than symfony!

tef
May 30, 2004

-> some l-system crap ->

Bloody posted:

right, that makes sense. I guess I don't get the "mark everything private and give it a getter and setter" thing that seems to be popular.

it's marking where you pass mutable data structures around :v:

ShadowHawk
Jun 25, 2000

CERTIFIED PRE OWNED TESLA OWNER
yospos what are your opinions about circular references in classes

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
for those who don't read the python thread, shadowhawk is most likely referring to something like this:

Python code:
self.equipment.owner = self

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

vapid cutlery posted:

do you have a better way to use Optional

let me tell you about do-notation,

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

ShadowHawk posted:

yospos what are your opinions about circular references in classes

do u like weak references?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Malcolm XML posted:

do u like weak references?

As much as I like __del__.

suffix
Jul 27, 2013

Wheeee!

ShadowHawk posted:

yospos what are your opinions about circular references in classes

you'll want them pretty quickly when you have a tree or other graph thing, and then they gently caress up your ~raii~

not worth avoiding imo, just never rely on the destructor and have a sensible way to unravel it if you don't have gc

tef
May 30, 2004

-> some l-system crap ->

Symbolic Butt posted:

for those who don't read the python thread

i gave up with that thread :v:

tef
May 30, 2004

-> some l-system crap ->
surprise: it's game dev code :toot:

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>

tef posted:

surprise: it's game dev code :toot:

you mean people will actually run it?

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

vapid cutlery posted:

you mean people will actually run it?

gamers aren't people

hepatizon
Oct 27, 2010

Mr Dog posted:

sometimes a struct is just a struct. other times validating data might be a good idea idk it seems to me like an object should always enforce its own validity so a setter would be a good place to perform validation.

mutable objects are the root problem

Soricidus
Oct 21, 2010
freedom-hating statist shill

hepatizon posted:

mutable objects are the root problem

this is truth

if you find yourself creating an object with a bunch of setters, and it's not a builder, you may possibly have hosed up

Sapozhnik
Jan 2, 2005

Nap Ghost

hepatizon posted:

mutable objects are the root problem

this is a good pragmatic rule

but if you get religious about it then you end up with haskell

were i to redesign java from scratch though i'd remove the final keyword and replace it by "mutable" instead. and i'd add unsigned types too, of course.

however, java isn't a plang and it's used for more important things than worthless startup fart app poo poo. so the stewards of java don't burn it all to the ground every three years because they want the bikeshed to be pink instead of blue this time.

Cybernetic Vermin
Apr 18, 2005

it is overall not that hard to just not mutate poo poo in java, it is even pretty trivial to write tools that statically verify that you don't where you say you don't (well, if you can assume that no code is dead or it is fine to disallow mutation even in dead code). so really the realization that mutating poo poo is bad is 95% of the battle

Cybernetic Vermin fucked around with this message at 21:56 on Dec 29, 2014

FamDav
Mar 29, 2008

Cybernetic Vermin posted:

it is overall not that hard to just not mutate poo poo in java, it is even pretty trivial to write tools that statically verify that you don't where you say you don't (well, if you can assume that no code is dead or it is fine to disallow mutation even in dead code). so really the realization that mutating poo poo is bad is 95% of the battle

the reason why i like have this just be part of the language is i'd rather let a compiler police this poo poo than elder devs (and in some cases the elders are part of the problem :( )

brap
Aug 23, 2004

Grimey Drawer
seriously. help the compiler help you.

brap
Aug 23, 2004

Grimey Drawer
plus the sap maintaining your code will be left wondering why there are methods that must not be called

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Cybernetic Vermin posted:

so really the realization that mutating poo poo is bad is 95% of the battle

This is massive in front end dev as well. With tools like React that now encourage you to really define your state versus immutable properties, the whole ball of wax becomes so much more maintainable.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Mr Dog posted:

but if you get religious about it then you end up with haskell

im not seeing the problem here

JewKiller 3000
Nov 28, 2006

by Lowtax

fart simpson posted:

im not seeing the problem here

that's because there isn't any, the immutability part of haskell is just fine. the problem is lazy evaluation

although sometimes it's nice to say "for this algorithm i'll need a contiguous array of memory whose cells i can mutate in constant time" and have your language respond with something other than "go gently caress yourself"

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

JewKiller 3000 posted:

that's because there isn't any, the immutability part of haskell is just fine. the problem is lazy evaluation

although sometimes it's nice to say "for this algorithm i'll need a contiguous array of memory whose cells i can mutate in constant time" and have your language respond with something other than "go gently caress yourself"

data.vector.mutable

JewKiller 3000
Nov 28, 2006

by Lowtax

Malcolm XML posted:

data.vector.mutable

Portability non-portable
Stability experimental
Maintainer Roman Leshchinskiy <rl@cse.unsw.edu.au>

tef
May 30, 2004

-> some l-system crap ->

Mr Dog posted:

however, java isn't a plang and it's used for more important things than worthless startup fart app poo poo. so the stewards of java don't burn it all to the ground every three years because they want the bikeshed to be pink instead of blue this time.

lol real programmers write business logic in an xml framework, none of this curly bracket poo poo

tef
May 30, 2004

-> some l-system crap ->

Mr Dog posted:

this is a good pragmatic rule

but if you get religious about it then you end up with haskell

were i to redesign java from scratch though i'd remove the final keyword and replace it by "mutable" instead. and i'd add unsigned types too, of course.

however, java isn't a plang and it's used for more important things than worthless startup fart app poo poo. so the stewards of java don't burn it all to the ground every three years because they want the bikeshed to be pink instead of blue this time.

public mutable void method () {
}

Brain Candy
May 18, 2006

tef posted:

public mutable void method () {
}

tbh would be nice to specify the things you are okay with being overridden because not designing for inheritance leads to awful inheritance

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

JewKiller 3000 posted:

Portability non-portable
Stability experimental
Maintainer Roman Leshchinskiy <rl@cse.unsw.edu.au>

its shipped with ghc, it's good enough

tef
May 30, 2004

-> some l-system crap ->

Brain Candy posted:

designing for inheritance leads to awful inheritance

fixed!

Brain Candy
May 18, 2006

just because inheritance is awful doesn't mean I'm not going to do it

Sapozhnik
Jan 2, 2005

Nap Ghost

tef posted:

lol real programmers write business logic in an xml framework, none of this curly bracket poo poo

nah that's another java strawman

tef posted:

public mutable void method () {
}

concrete inheritance is poo poo in most cases but there are few boilerplate-y things it's good at dealing with, provided you don't expose your data members like some sort of loving animal. in this imaginary cleaned-up java classes should be final unless explicitly declared otherwise (and then the same should be true of methods on top of that), and most of the time classes should be abstract, final, or an exception.

but yeah, most of the time. every now and again you come across a situation where a dirty solution like concrete inheritance is the least bad solution. early oop emphasised concrete inheritance heavily which we know now to be a mistake.

tef
May 30, 2004

-> some l-system crap ->
traits or die trying

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED

Bloody posted:

right, that makes sense. I guess I don't get the "mark everything private and give it a getter and setter" thing that seems to be popular.

this is really big in java because there is simultaneously a need to create consistent, long-lived interfaces and APIs and also a total lack of modern PL features for abstraction (surprise, it's because java has to be a consistent, long-lived interface). setters and getters are encapsulation at a really small scale.

for example, pretend you have this class in the first version of your application:

code:
class Foo {
    public Integer threshold;
}
later on you learn that you can actually support much more fine-grained thresholds, so you change the type to a Float. oh poo poo, all the clients' code that had "obj.threshold = 3" is now broken cause "int cannot be converted to Float." if you used setters/getters, it's no issue to have setThreshold(Integer x) and setThreshold(Float x) live side-by-side.

in conclusion, it's another practice that is a good idea in java because java's not that good of a language.

Pie Colony fucked around with this message at 19:04 on Dec 30, 2014

Adbot
ADBOT LOVES YOU

brap
Aug 23, 2004

Grimey Drawer
waaaaait, can you really not do an implicit widening conversion from int -> float

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply