deathbeam / spoon

:ramen: Spoon is a programming language that runs blazingly fast, compiles to native code and works everywhere.
https://spoonlang.org
MIT License
56 stars 11 forks source link

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

Open kobi2187 opened 8 years ago

kobi2187 commented 8 years ago

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:

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

escargotprodige commented 8 years ago

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

escargotprodige commented 8 years ago

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
kobi2187 commented 8 years ago

wow, I like your style. very aesthetic!

escargotprodige commented 8 years ago

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
kobi2187 commented 8 years ago

:+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 :-)

escargotprodige commented 8 years ago

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:

deathbeam commented 8 years ago

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,
  ],
]
escargotprodige commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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