Skip to content

Instantly share code, notes, and snippets.

@amontalenti
Created December 24, 2013 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amontalenti/8114359 to your computer and use it in GitHub Desktop.
Save amontalenti/8114359 to your computer and use it in GitHub Desktop.
example illustrating the complete lack of lightweight data modelling in Java
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
public class JavaMapsAndLists {
public static void main(String [] args) {
List<Integer> someItems = Arrays.asList(new Integer[] {1, 2, 3, 4});
for (Integer item : someItems) {
System.out.println(item);
}
Map<String, String> someMapping = new HashMap<String , String>() {{
put("ST", "started");
put("IP", "in progress");
put("DN", "done");
}};
for (Map.Entry<String, String> entry : someMapping.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + " => " + value);
}
}
}
@amontalenti
Copy link
Author

See https://gist.github.com/amontalenti/8114383 for the equivalent Python example -- not only is it 14 lines of code shorter and 35% the number of characters, but it is also much easier to read and requires no use of esoteric language features.

@wting
Copy link

wting commented Dec 24, 2013

FYI if you check out your gist as a repo you can add multiple files (but not directories). Here's an example.

@jpfuentes2
Copy link

@amontalenti
Copy link
Author

Clojure, a bit closer to other examples: https://gist.github.com/amontalenti/8117294

@lgastako
Copy link

Here's a version in haskell, though I am not really a haskeller, so I'm sure it can be better: https://gist.github.com/lgastako/8117999

@amontalenti
Copy link
Author

@asimjalis
Copy link

You can do lists this way to make it more concise.

List<Integer> someItems = Arrays.asList(1, 2, 3, 4);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment