Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. A solution for overloading (very bad now but might improve, a keyword called "dynamic")
- 2. Less verbose access to object fields and methods via the "expose" and "exposed" keywords
- 3. Ways to make method and field declarations easier (like how void methods don't need `void` to be specified).
- The `dynamic` keyword:
- Allows you to write patterns that define the possible ways a method can be called, in a set of argument names that are enclosed in square brackets to indicate that they are optional.
- See these examples:
- `dynamic[name, age, birthday] []` = you either specify all three arguments, or none.
- `dynamic[name, age, [birthday]]` = you either specify two arguments (`name`, `age`) or three arguments (`name`, `age`, `birthday`).
- `dynamic[name, [age], birthday] []` = you either specify none, or two arguments (`name`, `birthday`) or three arguments (`name`, `age`, `birthday`).
- To be easier to use, I also plan to add default values to arguments.
- Example in code:
- ```java
- // java with overloading
- public void move(int plane, boolean clockwise) {
- move(plane, clockwise, true);
- }
- public void move(int plane, boolean clockwise, boolean record) {
- super.move(plane, clockwise);
- if (record) {
- moveRecord.add(new Move(plane, clockwise));
- }
- }
- //my syntax without overloading
- public dynamic[plane, clockwise, [record]] move (int plane, boolean clockwise, record=false) { // any argument without a type is assumed to be the same type as the last element behind it
- super.move(plane, clockwise);
- if (record) {
- moveRecord.add(new Move(plane, clockwise));
- }
- }
- ```
- I know the syntax is bad and is even more confusing than overloading for now. I will find a better way, hopefully.
- Next is the `expose` keyword:
- It's simple. Any object that is "exposed" will have its methods accessible directly, like so:
- Normal Java code:
- ```java
- private void drawSquare(Vector2 position, Dimension2 size, Color color) {
- int width = size.getWidth();
- int height = size.getHeight();
- BufferedImage square = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = square.createGraphics();
- g.setColor(color);
- g.drawRect(position.getX(), position.getY(), width, height);
- g.dispose();
- canvas.addImage(square);
- }
- ```
- ```java
- private drawSquare(exposed Vector2 position, exposed Dimension2 size, Color color) { // exposing args objects, their fields as x, y are now accessible directly
- BufferedImage square = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // direct access to size.getWidth(), etc.
- Graphics2D g = square.createGraphics();
- expose g { // you can also make expose code blocks, now g methods are exposed
- setColor(color);
- drawRect(x, y, width, height);
- dispose();
- canvas.addImage(square);
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement