Advertisement
Guest User

Redundancy in programming Java

a guest
Dec 12th, 2015
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. As I learned Java over the years, my goal (and my carrying point) in programming has been, "Use the most efficient, non-lengthy way" to code. I have found that enough to keep me going, and my projects result in beautiful, small applications. Although, there is a lot of redundancy. I am actually wanting to create a compiler which does these things. By the end, I want to show you guys a few ways Java can change in Java 9 and minimalism the number of characters you have to type, using different examples. Thanks for reading! :)
  2.  
  3. Point 1: Parameter Declarations
  4. Example:
  5. void example(int a, int b, int c, int d, String e, String f, boolean g) {}
  6. Reason:
  7. Look at all those integers! Too bad we can't do... It is of everyone's best interest to do this.
  8. void example(int a, b, c, d, String e, f, boolean g) {}
  9.  
  10.  
  11. Point 2: Field declarations
  12. Example:
  13. public static final String s = null, d = "asd", e = "foo";
  14. public static final int a = 1, b = 2, c = 3;
  15. Reason:
  16. Do we really need to type public static final again and again when we are making fields, especially Enumeration-like classes?
  17. public static final (
  18. String s = null, d = "asd", e = "foo";
  19. int a = 1, b = 2, c = 3;
  20. )
  21.  
  22. Point 3: Imports
  23. Example:
  24. import java.lang.whatever.classa;
  25. import com.somesite.wasd.classb;
  26. import java.sun.dontusethis.time;
  27. etc.
  28. Reason:
  29. We don't need to declare import thousands of times just to get classes we need. It would be an added bonus if we could take portions of paths to the classes and cut it down.
  30. Example:
  31. import
  32. java.lang.whatever.classa;
  33. com.somesite.wasd.classb;
  34. sun.dontusethis.time;
  35. Example 2:
  36. import
  37. /java.lang
  38. whatever.classa;
  39. somesite.wasd.classb;
  40. /sun.dontusethis.time;
  41. To be more descriptive here, the '/' would represent a change in area of import. Since java.lang points to a package, rather than a class, it would be logical to indentify this change. Since / is on a class called time, it would not be redundant to utilize this, as it would break the scope of java.lang packages and classes.
  42.  
  43. I hope you guys see the added bonus in these 3 points. They reduce the effort you have to type. Since imports are automated, it could help the IDE you are using somewhat by adding implied logical sorting of key-value pairs when iterating. When declaring fields, it would be much simpler just typing some text out that means what the rest of fields will be. We don't need to type int thousands of times in a function, especially when we can't tuple that.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement