Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

05-09-2018 , 05:35 PM
Quote:
Originally Posted by PJo336
I had to listen to some java nerd go on about how great functional programming in it was. Ugh
in java 8 i've been using lambdas recently and honestly, they're not that bad.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 05:43 PM
Quote:
Originally Posted by jmakin
have you ever had this common mistake wreck absolute havoc at runtime and not understood why?

str += "foo";


this is fine for small strings. but if your string is say, the size of pride and prejudice (which happened to me recently) then it has to destroy and recreate the entire string just to append. you need to use stringbuilder to concat to a large string.

now, every java dev knows this and will avoid this mistake, but it's quite unintuitive that every method that modifies a string actually destroys the entire object and recreates it.

Lol, we had a stream process that built up a string to be written to a few diff places. We spent like 2 hours wondering why it ran so slow and it ended up being we could prepend rather than append strings.

I disagree with the wording that its about something being immutable though. Immutability is the bees knees and is a huge issue i have with a lot of java (things like passing a hash map into a function that returns void and modifying the hash map are terrible programatic practices that are encouraged in java)

Re: java 8, i have somewhat limited experience, but cramming a feature in (their "streams" that arent streams) 10 years after every other language (including php) is likely not enough to help me appreciate it.

All hate aside though, you are dead on with the libs. Especially Springs maturity. You can have a full api up in 10 seconds with dependency injection with 0 configuration files
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 05:46 PM
Java 8 is definitely way better than 7 in a lot of respects IMO, including functional interfaces, but yeah functional programming in java is just... very verbose.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 06:10 PM
yea, basically, java is my go to all-purpose language when i absolutely need to get something done quickly.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 06:16 PM
And yea i generally avoid hash maps when i can in java
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 06:25 PM
I dont think there is anything fundamentally wrong with java, or any language really. I just dont like when a languages "best practices" seem to go against the grain for well defined practices in general programming. Mutating stuff goes against the grain for me, and Java very much encourages that. Rails is much worse in that regard. Setting instance variables and randomly mutating them in methods because "thats the rails way". Ugh.

All stuff should be written in a way thats easy to read and understand whats happening for a developer coming in cold, but in practice that basically never happens. Thats actually the fundamental problem with functional programming (esp scala) imo.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 06:53 PM
Quote:
Originally Posted by Larry Legend
I'm finding as I get better at programming I'm writing significantly less code.

Well maybe not less overall, but per feature/bugfix.
I actually wrote tests in conjunction. Sometimes even before.

For real tho, it's bc I have a much better understanding of the code and design pattern.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 06:54 PM
Quote:
Originally Posted by Larry Legend
I'm not gonna lie, our backend is all Java and I don't really see a purpose in trying to learn it, but jmakin loves java and the jvm so much I may need to give this **** a try.
Do not do this.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 06:58 PM
Quote:
Originally Posted by Larry Legend
I'm not gonna lie, our backend is all Java and I don't really see a purpose in trying to learn it, but jmakin loves java and the jvm so much I may need to give this **** a try.
C# is like Java but a million times better. Linq alone is worth it

@jmakin, do you still need getters and setters in Java? Lol boilerplate.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 07:07 PM
Jmakin bringing the hot takes
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 07:42 PM
Quote:
Originally Posted by PJo336
I just dont like when a languages "best practices" seem to go against the grain for well defined practices in general programming. Mutating stuff goes against the grain for me, and Java very much encourages that. Rails is much worse in that regard. Setting instance variables and randomly mutating them in methods because "thats the rails way". Ugh.


(I know gaming_mouse agrees with you too )
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 08:34 PM
Lol, I definitely took it a bit too far in the scala hipster world, but I am coming back to earth a little. Probably not enough but alas. I just want code that changes stuff to be clear that its changing!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 08:36 PM
We don't need to go full immutability, but I think we can all agree that methods which mutate their parameters are the work of Satan.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 08:40 PM
Quote:
Originally Posted by ChrisV
We don't need to go full immutability, but I think we can all agree that methods which mutate their parameters are the work of Satan.


Aka every C string library function?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 08:46 PM
For example, yes.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 09:34 PM
Quote:
Originally Posted by goofyballer
Does RSU = stock grant (shares, not options)? Is your company public?

Related, saw this tweet recently:

https://twitter.com/danluu/status/942452212445405185

I assume the Lyft RSUs are way higher than the rest because they're probably the farthest of all these companies from being public (well, idk anything about Palantir), thus making those RSUs the most risky as far as "will this ever become money in my bank account"?

For public companies RSUs = money in the bank right?
Question about RSUs at private companies - I assume you still owe taxes on shares you're granted, right? For a high number of RSUs, couldn't that leave with you an absurdly high tax burden (like, ~40% of the value of the shares combining federal + CA tax) that you can't really sell your shares to pay for like you could at a public company?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 09:40 PM
Quote:
Originally Posted by ChrisV
We don't need to go full immutability, but I think we can all agree that methods which mutate their parameters are the work of Satan.
So never pass pointers, never modify the objects behind pointers within a method, or just make sure pointers are explicitly called out like in C++? Or other?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 09:48 PM
Most hard rules or views are the work of Satan. Mutability is ok if it's in a performance critical section of code. As for C, if you're not thinking/caring about minimizing the number of memory allocations, then you should be in higher level language in the first place.

Quote:
Originally Posted by PJo336
Mutating stuff goes against the grain for me, and Java very much encourages that. Rails is much worse in that regard. Setting instance variables and randomly mutating them in methods because "thats the rails way". Ugh.
Never heard that poor OOP design being referred to as "the Rails way".
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 10:37 PM
in ruby if you do

x = 5

x + 1 returns 6

but x is still 5

there are some methods that will mutate the object. they are available but i'm not sure it is fair to say that they are encouraged.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 10:50 PM
Quote:
Originally Posted by :::grimReaper:::
Never heard that poor OOP design being referred to as "the Rails way".
Id assume the mutation aspect isnt "The Rails Way", but you see it a lot (updating a user field in a user service or something).

Common pattern I dont care for

Code:
class FooService
  def initialize
    @foo = Foo.new()
  end

  def method_100_lines_later
    # Do something with @foo here, mutating or just reading
  end
end
I had code that didnt pass review bc my service looked more like:

Code:
class FooService
  def method_100_lines_later(foo)
    # Do something with foo here, mutating or just reading
  end
end
I dont care for the former pattern, especially on a big app.

And obviously there are considerations for a rule. I tried doing 100% immutable but that was just stupid annoying and slows you down on anything with a slight bit of logic to it.

Quote:
Originally Posted by OmgGlutten!
in ruby if you do

x = 5

x + 1 returns 6

but x is still 5

there are some methods that will mutate the object. they are available but i'm not sure it is fair to say that they are encouraged.
I specifically said rails, and you did no mutations there of any sort.

Im more butthurt by the private or self modifier being on one random line in bigger files than any of this stuff btw
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 11:16 PM
Quote:
Originally Posted by suzzer99
So never pass pointers, never modify the objects behind pointers within a method, or just make sure pointers are explicitly called out like in C++? Or other?
That. I mean, "never" is a big word, but it's typically bad practice. Allowing it ruins the abstraction because I then have no idea whether my parameters on a method call are going to be mutated or not without consulting the code of the method. Some third party code did that to me in Java the other day, took me a little while to track down debugging. Not happy.

On the extremely rare occasion I want to mutate parameters in C#, I always declare the parameter with the "ref" keyword, which makes a pointer reference pass, even if I don't actually need a pointer reference, just to alert any users of the function that their parameter is not safe from mutation.

You know what would be nice in C# and Java? An "immutable" keyword on method declarations, giving a compiler-checked assurance that parameters will not be mutated.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 11:26 PM
Quote:
Originally Posted by ChrisV
On the extremely rare occasion I want to mutate parameters in C#, I always declare the parameter with the "ref" keyword, which makes a pointer reference pass, even if I don't actually need a pointer reference, just to alert any users of the function that their parameter is not safe from mutation.
But then they'll think that your function might change the object that the variable is pointing to!

Quote:
Originally Posted by ChrisV
You know what would be nice in C# and Java? An "immutable" keyword on method declarations, giving a compiler-checked assurance that parameters will not be mutated.
C++ and "const" for the win
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 11:28 PM
Quote:
Originally Posted by :::grimReaper:::
Most hard rules or views are the work of Satan. Mutability is ok if it's in a performance critical section of code.
Anything ever said about software design has this caveat. I can say that the use of GOTO is terrible software design without having to add a footnote about JUMP instructions in assembly.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 11:33 PM
Quote:
Originally Posted by goofyballer
But then they'll think that your function might change the object that the variable is pointing to!
Yeah. I'd rather they thought this than that they had no idea their object might get mutated. The message is "I'm going to do whatever I like to this variable, plan accordingly".

When I say "I always do this", I mean I've probably done it like twice in my career, because there's virtually always a better way to write the code.

Edit: I suppose people might just think they'll be safe making a copy of the pointer before passing, so maybe it's a bad idea. There's unfortunately no good way to deal with it in the language.

Quote:
C++ and "const" for the win
I've never written C++, does this actually work?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
05-09-2018 , 11:41 PM
Quote:
Originally Posted by ChrisV
I've never written C++, does this actually work?
Yes, very well.

Code:
void myFunction(const std::string& str) { ...
Code inside this function can't modify str (or else compiler error). Additionally, you can mark individual class methods as const - example for std::string:

Code:
class string {
public:
  ...
  void clear(); // clears the string contents; not a const method
  size_t size() const; // returns length; is a const method
  ...
};
...which means those methods can't modify members or do non-const operations on them (or else compiler error). If you have a const variable as in the first snippet (myFunction), you can ONLY call const methods on it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m