spoon icon indicating copy to clipboard operation
spoon copied to clipboard

Suggestion: Use and Expand list literals in code (compile time)

Open kobi2187 opened this issue 10 years ago • 10 comments

When looking for packages or including interfaces, use the list literal [ list literal ]. And then expand to single lines.

class @ :: Hello :: World
  def @main() do new @@()

  def new()
    hello()
    world()
  end
end

the first line becomes: class @ :: [ Hello , World ]

the same should be done for import.

import openfl.display.Bitmap
import openfl.display.Sprite
import openfl.events.Event
import openfl.events.KeyboardEvent
import openfl.ui.Keyboard
import openfl.Assets

can be written as:

import openfl.display.[ Bitmap, Sprite ]
import openfl.events.[ Event, KeyboardEvent ]
import openfl.ui.Keyboard
import openfl.Assets

This means to parse the line and create multiple lines according to the list part. that is, expand it.

other possibilities for syntax:

  • slash - because it signifies directories: import openfl/events/[ Event, KeyboardEvent ]
  • Allow regular expressions between parts: import openfl.(events|ui).something #something is in both of them. can have other .* regular expressions. This will mean that raxe will have to scan the directories or packages to retrieve everything that matches.

While we're on this subject of reducing code amount, the word "import" repeats every line. what do you think about something along these lines?

import {
    openfl.display.[ Bitmap, Sprite ]
    openfl.events.[ Event, KeyboardEvent ]
    openfl.ui.Keyboard
    openfl.Assets
}

seems cleaner to me

kobi2187 avatar Nov 04 '15 17:11 kobi2187

:+1: That is an amazing idea :smile:

escargotprodige avatar Nov 05 '15 17:11 escargotprodige

This is my suggestion for the last one. It reduces even more code & looks more like raxe syntax :smile:

import
  openfl: 
    display: Bitmap, Sprite
    events: Event, KeyboardEvent
    ui: Keyboard
    Assets
end

escargotprodige avatar Nov 05 '15 19:11 escargotprodige

wow, I like your style. very aesthetic!

kobi2187 avatar Nov 05 '15 19:11 kobi2187

Following the same idea, this:

import luxe.Input
import luxe.Scene
import luxe.Sprite
import luxe.Visual
import luxe.Color
import luxe.Vector
import luxe.AppConfig
import luxe.Particles
import luxe.Entity
import luxe.Text
import luxe.structural.Pool
import luxe.structural.Bag
import luxe.options.GeometryOptions

import states.*

import mint.Control
import mint.types.Types
import mint.render.luxe.LuxeMintRender
import mint.render.luxe.Convert
import mint.layout.margins.Margins

would become:

import 
  states: *
  mint:
    render.luxe: LuxeMintRenderer, Convert
    layout.margins: Margins
    types: Types
    Control
  luxe:
    structural: Pool, Bag
    options: GeometryOptions
    Input, Scene, Sprite
    Visual, Color, Vector
    AppConfig, Particles, Entity
    Text
end

escargotprodige avatar Nov 05 '15 20:11 escargotprodige

:+1: very cool. one last final touch: I notice that package and class names can't have spaces in them, so it will not be ambiguous to remove the ',' commas and use whitespace (space or tabs) as separation. ok, maybe i'm taking this too far already. I like your syntax suggestions they look nicer than the original proposal in my opinion. good job :-)

kobi2187 avatar Nov 05 '15 21:11 kobi2187

Thanks :smiley: In my opinion, I think the separation is easier to see with the commas, but it could be optional, so it fits everyone's style :smile:

escargotprodige avatar Nov 05 '15 21:11 escargotprodige

This

import 
  states: *
  mint:
    render.luxe: LuxeMintRenderer, Convert
    layout.margins: Margins
    types: Types
    Control
  luxe:
    structural: Pool, Bag
    options: GeometryOptions
    Input, Scene, Sprite
    Visual, Color, Vector
    AppConfig, Particles, Entity
    Text
end

Looks more like CoffeeScript object notation, what about this? I know I am adding useless things there, but it is just because to make sense

import [
  openfl.[
    display.[ Bitmap, Sprite ],
    events.[ Event, KeyboardEvent ],
    ui.Keyboard,
    Assets,
  ]
]

So the first example would become this:

import [
  states.*,
  mint.[
    render.luxe.[LuxeMintRenderer, Convert],
    layout.margins.Margins,
    types.Types,
    Control,
  ], luxe.[
    structural.[Pool, Bag],
    options.[GeometryOptions],
    Input, Scene, Sprite,
    Visual, Color, Vector,
    AppConfig, Particles, Entity,
    Text,
  ],
]

deathbeam avatar Nov 06 '15 12:11 deathbeam

I think that both of the solutions are great, the only problem is that there is not enough people to discuss about it :worried: To me, the fact that it looks like CoffeeScript object litterals doesn't really matter. In fact, I think looks cleaner.

But like I said, there should be more people to discuss about that :smile:

escargotprodige avatar Nov 06 '15 16:11 escargotprodige

I think we should improve the LiveScript require! syntax so that it fits Spoon and Haxe to reduce the ammount of import statements.
I hate big import lists and the current Spoon syntax for import statements doesn't help :smile:

escargotprodige avatar Nov 24 '15 14:11 escargotprodige

Regarding the new syntax for import, I've reworked the syntax found here and opened #26 so that we can discuss it together :)

escargotprodige avatar Dec 12 '15 17:12 escargotprodige