java: libraries for immutable functional-style data structures [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
This is very similar to another question (Functional Data Structures in Java) but the answers there are not particularly useful.
I need to use immutable versions of the standard Java collections (e.g. HashMap / TreeMap / ArrayList / LinkedList / HashSet / TreeSet). By "immutable" I mean immutable in the functional sense (e.g. purely functional data structures), where updating operations on the data structure do not change the original data, but instead return a new instance of the same kind of data structure. Also typically new and old instances of the data structure will share immutable data to be efficient in time and space.
From what I can tell my options include:
Functional Java
Scala
Clojure
but I'm not sure whether any of these are particularly appealing to me. I have a few requirements/desirements:
the collections in question should be usable directly in Java (with the appropriate libraries in the classpath). FJ would work for me; I'm not sure if I can use Scala's or Clojure's data structures in Java w/o having to use the compilers/interpreters from those languages and w/o having to write Scala or Clojure code.
Core operations on lists/maps/sets should be possible w/o having to create function objects with confusing syntaxes (FJ looks slightly iffy)
They should be efficient in time and space. I'm looking for a library which ideally has done some performance testing. FJ's TreeMap is based on a red-black tree, not sure how that rates.
Documentation / tutorials should be good enough so someone can get started quickly using the data structures. FJ fails on that front.
Any suggestions?

It seems to me you already know what your options are, you just aren't happy with any of them. Here is my take on the three choices you've provided:
Functional Java - This one seems like the best fit for you. It fits all of your requirements except that you don't like the documentation. From my perspective the documentation looks basic, but serviceable. Their code snippets should get you up and running quickly. The learning curve seems almost non-existent which should help mitigate the lack of documentation. FYI, core Java's TreeMap is based on a Red-Black tree as well.
Scala - This is the choice I would make if I was in your shoes. You seem to not want to learn a new language, but Scala is a very easy transition from Java. You can write very java-like code at first, and slowly adopt more functional idioms. The Java <-> Scala interop is excellent in both directions as well.
Clojure - As much as I love Clojure, its tough to recommend in this particular instance due to the radically different syntax and steep learning curve for a java developer.

Perhaps Google's guava-libraries may be of some use:
https://code.google.com/p/guava-libraries/wiki/ImmutableCollectionsExplained

Scala
You can call the methods of either language from methods in the other one
http://www.scala-lang.org/faq/4

I've spent some time making the Clojure persistent/immutable data-structures work in Java, with sensible constructors and generics as part of Pure4J.
This also includes #ImmutableValue class for ensuring that not only are the collections immutable, but the values you put in them are immutable too.
Hope this helps.

Related

Advice for how Java classes should be organized [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm fairly new to Java but love it so far. My question is, i'm a little unfamiliar with Classes. I know what they are, and generally how to work with them as I'm not brand new to programming, but I would like a professionals opinion.
I'm currently writing a small multi threading program to launch parallel power shell sessions by spawning cmdlines for target machines in a csv, capture the output and write to a csv.
Should I put everything into one class and breakup the logical operations to methods within the class and string them together? Or should I make a Thread executor class, cmdline powershell class, a csv operations class, etc (My thought behind that was to allow code reuse, but that'll be kindove time consuming and in my mind impractical since i'd have to specify the datatypes and return types for new situations in the future).
Any help would be appreciated!
There is no "way" so to speak,
It's all your preference.
But just don't cram everything into one class.
Generally, you want to be as neat as possible.
In the future, you will thank yourself for using different classes.
If your project grows, and a bug is born, you don't want to be looking through one very long class, but instead simple broken up pieces.
Let's say you have these classes:
GPS,
Main,
Search
And someone reports a bug with the GPS not working.
Instead of looking everywhere saying, where did I put the GPS code,
it's right in front of your eyes!
I've went to everyones links and found the info very helpful. So far I've come up with this.
Make a package that contains classes that perform a specific set of tasks (also don't make utility kits that are very general). The package in my case would be called com.jt.threads.powershell or something.
Keep classes small and breakup the program by conceptual types. (ie. data reading and writing operations on a filesystem should be in one class with the focus on helping the package perform a certain task or range of tasks.)
Methods within classes should focus on getting, setting, changing the objects attributes or adding logic.
The program entry point should join it all together, except in the case of large applications, in which case an interface should be used (still learning about them).
With true OOP, i don't think it's a good idea to create code for reuse, unless it's supporting a range of very very very similar tasks (that way if I have to change something, it won't break other classes outside of the package).
Thank you all! I feel a lot better knowing that I'm on the right track. I was worried that by NOT making code reusable in a lot of situations that I was doing something wrong. I started programming in Python 6 months ago for my job, but I totally ignored classes and I want to have good programming habits and apply OOP as best I can going forward! Python is definitely convenient and a great starter language, but I wish I learnt Java first so I can get a solid grasp on OOP.
There is no “The way” to organize or group classes. Anything goes as long as it works as expected and you understand what you write.
As a Programmer you only need to,
1. Know and understand what you write.
2. Know and understand what other Programmer as written.

Why do Java and C++ have syntactical similarities? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I noticed that C++ and Java seem to have many features in common in terms of syntax, although I would assume them to be fairly different languages. For example, both languages support casting and define functions by specifying the return type and then the name of the function. The for loops also seem very similar. Also, they both use curly braces for a variety of statements and structures.
Is there a reason for this? Did Java and C++ have some common predecessor, or was the syntax of one based on the other, for example? Or am I just reading too much into this?
Java is just a member of the family of C-style languages (i.e. the languages syntactically based on C Programming Language). The family includes languages like
C++, Java, JavaScript, PHP, Perl
which were very popular, for example, in 1990-s and the beginning of 2000-s.
Today's popularity of
Python, Ruby, Rust, Kotlin, Swift and others.
slightly moved the focus away from C-style languages. One of the reasons to move away from C-style is that C has context-dependent grammar and the new languages tend to have almost context-independent grammar, which makes its parsing easier and more predictable.
Anyone designing a new language would have nothing to gain by using different syntax for the same operations. So if the potential users of the language are, for example, used to "a++" being a variable "a" whose value increments but returns the existing value of a, or they're used to braces being what delimits a block of code, there's no reason for a new language not to use those same things. If this new language did switch these things, up, they risk potentially confusing and discouraging people from using it.
This extend not just to Java and C++, but some other languages as well. For example, JavaScript and Perl use many of the same syntax features that Java and C++ do.

Garbage-collected languages with efficient numeric data types [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am searching for a language/library (preferably JVM-based) that handles numeric values (integer and floating point numbers) in both convenient and efficient manner.
Convenient: supported by the collection framework and generics.
Efficient: incurs no noticeable overhead when the primitives are the
building block in a data-heavy data-processing software
(specifically, processing multiple GB of texts with >100,000,000
items).
Deficiencies of the current languages:
Plain Java: auto-boxing is quite convenient, but it has substantial
overhead.
Scala and Kotlin: seem to rely also on Java's boxed
primitives, so no efficiency advantage here.
Python: again, seems to box all numeric values, and we ran into prohibitive performance problems with vanilla Python. Numpy, which provides a different implementation, does not support the needed features.
Is there a language that handles primitives with the same convenience but efficiently (compared to that language general performance)?
C# fits the criteria, depending on what you mean by the efficiency requirement. It doesn't run on the JVM, of course.
Unlike Java, which implements generics with type erasure, C# implements generics via reification like C++ does. That means that when you make a List<int>, the underlying array will be an array of int, not an array of objects. Also the code that implements all the List methods will be compiled specifically for List<int>, and can take advantage of int-specific optimizations.
For this reason, data processing with primitive types is generally faster in C# than it is in Java when you're using all the convenient language features. It can still be far from what you can get with C++, however, because the runtime checks that prevent buffer overrun, etc., are not free.

Binding, glue code and wrapper library [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I many times saw terms binding, glue, and wrapper in a similar context and meaning(if we are talking about some "adapter code"). So what exactly means each of these terms? Is it a synonyms? Or what is the difference?
binding, wrapper and glue are - in this context specifically - are all sort of synonyms of each other and can sort of be used interchangeably..
bind, wrap and glue are all verbs which mean they're a word to describe an action, state or occurrence; even more-so they all revolve contextually around attachment. So yes - they are synonyms as far as the english language is concerned. However, concerning programming and the written paradigms used to describe ones actions within it may become more 'grey'.
Let us use an example. Directx and c#:
binding by definition is to "tie or fasten" something to something else, as is glue and to a lesser (but still valid) extent wrap. Which makes sense in this example as dx is is written and designed for c++, but there are libraries that wrap the c++ code providing a useable library for c# programmers to use; inside which, the code binds or glues the original c++ code to the c# equivalent - and vice versa - allowing these two (originally incompatible) sources to communicate.
So in using the c# alternative allows us access to the - if fully featured - functionality of the original c++ version.
So when talking about a wrapper one can refer to the base as binding or glue code. However - in my opinion - wrapper is a much broader term contextually, of which contains the actions of binding and 'gluing'.
This is my understanding - if somebody believes me mistaken, please don't hesitate to correct me.

Persistent data structures in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I need a persistent storage in Java for certain (possibly large) data structures, such as:
dense and sparse matrices of integers, doubles, booleans
directed graphs with labeled nodes and edges
binary trees
maps: string->string, string->integer (with fast retrieval of the keys with largest values)
sets of integers or strings
I don't mind if there is a separate storage for each data structure, as long as all the storages have similar, consistent interfaces.
I need to be able to efficiently modify the data structures "remotely", that is, without fetching the entire structure to RAM, modifying it, and storing back. Example operations: put a key-value in a map, remove a node from a tree, modify a node's label in a graph, add a value to a set.
It would be very nice if these storages could be also easily accessed from other programming languages, most notably Python. I'm thinking of a RESTful service in the backend and client APIs in Java and Python.
Motivation: I need to process a large collection of documents and perform various analyses on them. I want to explore various approaches and create fast prototypes (for that reason I need simple, easy-to-use APIs).
I guess I'm not the first person needing such a functionality and I would hate to reinvent the wheel here. Which brings me to the question: which open-source solutions allow easy-to-use persistence of data structures in Java?
Thanks in advance!
Have you thought about using something like MongoDB? It seem perfect for what your looking for and Its picking up a lot of steam. It's a high-performance, schema-free document-oriented database and I love the fact it's based on json! Check it out!
Here is nice Java tutorial.
How about ObjectOutputStream and ObjectInputStream?
It's very hard to wire all that but you can use JPA with bi-directional mappings and lazy-loading.
It would really depend on you usage patterens, i.e., how many reads, how many writes, how often, etc, but I would suggest you just use sql until you prove that it will not work.

Categories

Resources