Created
December 24, 2013 14:53
-
-
Save amontalenti/8114359 to your computer and use it in GitHub Desktop.
example illustrating the complete lack of lightweight data modelling in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
FYI if you check out your gist as a repo you can add multiple files (but not directories). Here's an example.
Clojure, a bit closer to other examples: https://gist.github.com/amontalenti/8117294
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
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
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.