News for hackers. Stuff that matters.
Re:Java garbage collection can be really slow by na85 on Saturday April 23, 2016 @10:47AM (#11555725)
If you're disabling GC, why use Java at all?

That's the point of using Java (or any interpreted language), isn't it? Avoiding manual memory management?

If you're going to go through all that horrid FactoryFactory Factory = new FactoryFactory(); bullshit, might as well get the benefits of the GC.

And if you don't want the GC, why not write your code in something else?

Re:Java garbage collection can be really slow by recursive on Saturday April 23, 2016 @11:04AM (#11555819)
> If you're going to go through all that horrid FactoryFactory Factory = new FactoryFactory();

I get the impression that your only exposure to java is through jokes and blogs from dynamic typing evangelists.

Re:Java garbage collection can be really slow by nv-vn on Saturday April 23, 2016 @11:31AM (#11555953)
How would that show any connection to dynamic typing? I imagine that the GP is coming from the perspective of C based on the fact that they're criticizing the use of garbage collection.
Re:Java garbage collection can be really slow by na85 on Saturday April 23, 2016 @02:18PM (#11556667)
You'd be incorrect.
Re:Java garbage collection can be really slow by tinco on Saturday April 23, 2016 @11:42AM (#11555988)
There are no popular languages that both have no GC and are comfortable to work in. Rust is going to be one, though I feel it's not entirely comfortable yet.

Garbage collection is just one of the things that make languages like Java comfortable to work in, but certainly not the only thing. Disabling automatic garbage collection in Java or C# I feel is a very effective way of gaining most of their advantages while limiting the effects of the runtime on the variability of your execution time.

Java is not an interpreted language by the way. FactoryFactories are a choice, not necessarily forced by the language.

Re:Java garbage collection can be really slow by ryao on Saturday April 23, 2016 @01:22PM (#11556433)
How is your statement not one by someone who would find the modification of any language considered comfortable to remove garbage collection and require explicit free operations to render it uncomfortable?

Also, Java is interpreted at the byte code level by default. The way the hotspot JIT works is by detecting hot areas of code and then doing JIT to be compiled.

Re:Java garbage collection can be really slow by ScottBurson on Saturday April 23, 2016 @03:06PM (#11556947)
What sense does it make to speak of a language as being interpreted or compiled? These are attributes of an implementation. The existence of GCJ, a native-code Java compiler that's been around for years, proves this.

It's true there are languages that are essentially uncompilable, and so have to be interpreted. Perl is the best example I can think of; there are constructs in the language that can't be parsed correctly without runtime context. Python, Ruby, and JavaScript are all difficult to do AoT compilation on as well, at least if you want to do much optimization, but I wouldn't agree that they can't be compiled. But Java is not as dynamic as these languages.

Re:Java garbage collection can be really slow by ryao on Saturday April 30, 2016 @12:44PM (#11602404)
When talking about Java, you can mean the standard library, the virtual machine or the language. The term Java itself is ambiguous.
Re:Java garbage collection can be really slow by tinco on Saturday April 23, 2016 @02:25PM (#11556698)
I don't think it must be absolutely so that a language without garbage collection is uncomfortable, as I said I feel Rust comes very close.

The only popular languages without a garbage collector are either from the 70s (C) or based on a language from the 70s (C++xx). Both have extreme discomforts when compared to modern languages (Ruby/Haskell/C#/Rust).

Also, technically, that would make Java bytecode an interpreted language, not Java itself ;)

edit: Ok, apparently according to wikipedia I am wrong and Java generally is considered to be an interpreted language, I had a slightly different definition of interpreted in mind.

Re:Java garbage collection can be really slow by Roboprog on Saturday April 23, 2016 @02:44PM (#11556804)
Yeah, when C displaced Pascal in CS programs (mid to late 80s?), it felt like an uncomfortable step backward even then.

Why were we programming in (little more than) assembler as our main language???

Re:Java garbage collection can be really slow by pjmlp on Saturday April 23, 2016 @03:03PM (#11556937)
Mid to late 90's in Portugal.

When I came to learn C, I was already quite an expert in Turbo Pascal, version 6.0 by then.

Comparing C to Turbo Pascal 6.0 in terms of features and safety just felt like "meh!".

Thankfully I got someone that around the same time gave me a copy of Turbo C++ 1.0 and I learned how to get some of the Turbo Pascal features back, while having the C portability and joined the C++ ranks for a few years.

Re:Java garbage collection can be really slow by Roboprog on Saturday April 23, 2016 @03:54PM (#11557145)
Similar experience. I picked up a copy of TP 5.5 and finally had an easier way to build my "ADT"s (abstract data type library type code).

THEN, I got a copy of TC++ a few months or a year later. WTF?!?

The light came on when I read Scott Meyer's "Effective C++" book in 96 or so. "Effective" meant "not stepping on one of 50 or so common land mines". I realized what a bad joke C++ was, and decided never to go back to it.

C is useful as a substitute for assembler, but not most applications. Too bad we didn't get to see more of Smalltalk in school in the 80s. And maybe Scheme instead of just a little bit of Lisp.

Re:Java garbage collection can be really slow by ryao on Saturday April 30, 2016 @02:19PM (#11602838)
C++ first came into existence in 1983. C was made in the 1970s and was the basis for C++, but modern C is rather different than the original C because it assimilated C++'s strong type system. As for popular languages without a garbage collector, here is a list off the top of my head:

* C

* C++

* FORTRAN

* Objective C

* Objective C++

* Pascal

* Swift

Making a new Turing complete language is ultimately just an exercise in how to do the same things differently rather than better unless you find a way to construct a language that can use hardware more effectively than the existing languages can. Languages that lack garbage collection provide no incentive to wipe the slate clean for easier garbage collection.

There is an enormous difference between expert level use of C and languages like it and beginner use. There are static analysis and dynamic analysis tools that have been built to assist with catching bugs such as misuse of memory or undefined behavior. C and several others that I listed above are flexible enough that you can implement design patterns that you would expect to see in more "advanced" languages and with structured programming, you can use them fairly easily once they are written. Functional programming is doable:

https://github.com/cioc/functionalC

Object oriented programming is also doable:

http://ooc-coding.sourceforge.net

Generic programming can also be done using a mix of macros and void pointers. A rather powerful design pattern that I have seen in C is a function that encapsulates iteration on some data and invokes a callback that takes an accumulator that had been passed to it with the callback. It is great for iterating over things that are not expected to always fit in system memory. The non-accumulator version of that pattern is used in the POSIX standard ftw C function. The acculumator version feels much like generic programming as the type of the accumulator is known only to the caller and callback. The iteration function has no clue about the acculumulator's type. The same goes for plenty of in-memory data structures implemented with void pointers like lists and trees where the memory describing each node is encapsulated inside the object.

There is definitely a greater learning curve to C and languages like it, but once you are faililiar with the right patterns/abstractions, such languages are a joy to use and the advantages of more "advanced" languages look more like trade-offs rather than be killer features.

Also, people who are familiar with such languages tend to program differently. At work, I have been asked to write some userspace code in Go. I wanted to make some directory traversal code use as few CPU resources as possible (which is a design goal), so I asked for tips on how to do system calls from Go and horrified at least one Go programmer in #go-nuts on freenode in the process. Using the syscalls directly enabled me to take advantage of SYS_gentdents64's d_type to avoid doing a stat to determine whether an entry is a directory or not, increase the buffer to read more directory entries per syscall fewer calls per directory and detect when the end of directory by checking when the buffer has 65535 bytes of free space remaining, which reduces the verse the invocations from 2 to 1. A programmer that does everything the way that garbage collected language authors recommend likely would have had a far less CPU efficient traversal. The superfluous stat syscalls alone would have increased the number of syscalls by at least 1 order of magnitude.

I wrote a patch to glibc last night that enables readdir() to skip the second getdents64 call on small directories and I plan to submit after I have what I consider to be the final version. That ought to accelerate GNU find. I might give the Go OS package similiar treatment, although doing fast directory tree traversal the way I am doing it (which is similiar to what GNU find does) requires that to go OS package provide type information from getdents. That is a non-portable BSD extension that Linux adopted and consequently is something that I would not expect Go to provide.

Re:Java garbage collection can be really slow by asveikau on Saturday April 23, 2016 @12:01PM (#11556077)
Comfortable is a relative term. There are people comfortable working in C or C++.
Re:Java garbage collection can be really slow by tinco on Saturday April 23, 2016 @02:44PM (#11556801)
True, there's a relevant photograph here[1]. Although I think that even those when they fall asleep or otherwise let their guard down their programming experience can get real uncomfortable real quick.

1] https://en.wikipedia.org/wiki/Bed_of_nails#/media/File:RGS_1...

Re:Java garbage collection can be really slow by na85 on Saturday April 23, 2016 @02:19PM (#11556676)
>Java is not an interpreted language by the way.

Java compiles to native machine code?

Re:Java garbage collection can be really slow by ysleepy on Saturday April 23, 2016 @02:32PM (#11556736)
Most of the time yes. The JIT will generate machine code for almost all usual code paths after little time.
Re:Java garbage collection can be really slow by pjmlp on Saturday April 23, 2016 @03:04PM (#11556943)
Yes, it all depends which JDK you make use of.

Apparently many seem to think the OpenJDK is the only option available.

Re:Java garbage collection can be really slow by exception_e on Saturday April 23, 2016 @12:29PM (#11556191)
That factory code you mentioned isn't _just_ a Java thing, but a very well-known and wonderful design pattern.

Wikipedia says it best: "[The] Factory pattern deals with the instantiation of object without exposing the instantiation logic."

Practical benefits:

- Can help rid of excessive switch and if/elseif statements and splits up your logic

- Eliminates new keyword to improve testability

Re:Java garbage collection can be really slow by anonymousab on Saturday April 23, 2016 @02:23PM (#11556693)
As with most language jokes/prejudices, I think the hate comes from seeing the misguided, incorrect or unnecessary uses of that pattern.

Java's prominence in the corporate world means sturgeon's law is more apparent.

Re:Java garbage collection can be really slow by exception_e on Saturday April 23, 2016 @02:25PM (#11556700)
Never heard of that law. Brilliant.
Re:Java garbage collection can be really slow by gravypod on Saturday April 23, 2016 @11:07AM (#11555834)
If you give Java a try, it's got a lot more impact than Factory. Play around with the language a bit, there are things in the JVM and the language that really change the way you think about programming.
Re:Java garbage collection can be really slow by Roboprog on Saturday April 23, 2016 @02:31PM (#11556731)
Sure. I now know:

* What a great feature function pointers / procedural types / other call-by-name/reference-mechanisms were. (J8 lamdas are used like function references, but are kind of heavy)

* What a source of mystery "annotations" are.

Java started out like an interpreted version of Delphi or UCSD Pascal disguised as a cleaned up C++, but since 1.1 it evolved slowly and/or in the wrong ways.

Actually, as somebody who has been programming since 1983, in quite a few languages, Java brought little to nothing new to the table. Nothing personal against you, I'm just sick of the Java language/syntax and how it failed to live up to the hype.

Re:Java garbage collection can be really slow by smac8 on Saturday April 23, 2016 @12:52PM (#11556286)
I'm a fan of Java in some senses, but curious to here what things you discovered in the language or JVM that changed how you thought about programming
Re:Java garbage collection can be really slow by ysleepy on Saturday April 23, 2016 @02:35PM (#11556756)
For me it is the vastly superior tooling.

* Best IDEs around. (Yes better than .net ecosystem)

* JVM monitoring (Flight Control, VisualVM)

* Performance Sampling/Profiling <1% perf cost

* actually being cross platform (yes, mono, bla)

Re:Java garbage collection can be really slow by threeseed on Saturday April 23, 2016 @06:13PM (#11557653)
Ability to use Clojure, Scala, Freje, Groovy, Java, Javascript, Python etc all on the one platform and share libraries and objects between each other.

People forget that Java has the best ecosystem of libraries bar none especially when you get into the more enterprise areas e.g. Big Data.

Re:Java garbage collection can be really slow by gravypod on Saturday April 23, 2016 @11:15PM (#11558407)
One-and-done is my favorite way of thinking about using Java. The JVM provides the perfect, for my use case, amount of abstraction from the hardware while still allowing you to do some amazing things.

There is also a huge amount of features that are supported by the JVM that Java still doesn't make use of.

There is also a great JIT and garbage collector.

Re:Java garbage collection can be really slow by smac8 on Tuesday April 26, 2016 @11:26AM (#11572650)
Yes, but I suppose this is more the JVM than the language itself. The JVM is quite convincing though, hence Clojure, Scala, etc.
Re:Java garbage collection can be really slow by Roboprog on Saturday April 23, 2016 @02:38PM (#11556769)
Because Java is the new COBOL -- especially if you statically allocate everything for performance reasons. At that point, you really are left with something not unlike COBOL with separate compilation and the ability to allocate scratch counters (or other primitives) on the stack locally, but all of your main data is still copy books^H^H^H^H^H^H^H beans allocated in the DATA DIVISION.