Jump to content

Which API design style do you prefer?  

25 members have voted

  1. 1. Which option below feels better to you?

    • Option A
      7
    • Option B
      18
  2. 2. How much programming experience do you have?

    • None or a little
      7
    • Medium amount
      11
    • A lot!
      7

This poll is closed to new votes


Recommended Posts

Posted

Please examine these two examples carefully, and tell me which one feels better to you?

Option A

--Get the displays
local displays = GetDisplays()

-- Create a window
local window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[1], WINDOW_CENTER + WINDOW_TITLEBAR)

-- Create a world
local world = CreateWorld()

-- Create a framebuffer
local framebuffer = CreateFramebuffer(window)

-- Create a camera
local camera = CreateCamera(world)
SetCameraClearColor(camera, 0.125)
SetEntityPosition(camera, 0, 0, -2)

-- Create a light
local light = CreateBoxLight(world)
SetEntityRotation(light, 45, 35, 0)
SetLightRange(light, -10, 10)
SetEntityColor(light, 2)

-- Create a model
local model = CreateBox(world)
SetEntityColor(model, 0, 0, 1)

-- Main loop
while not WindowClosed(window) and not KeyDown(window, KEY_ESCAPE) do
    TurnEntity(model, 0, 1, 0, true)
    UpdateWorld(world)
    RenderWorld(world, framebuffer)
end

Option B

--Get the displays
local displays = GetDisplays()

-- Create a window
local window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[1], WINDOW_CENTER + WINDOW_TITLEBAR)

-- Create a world
local world = CreateWorld()

-- Create a framebuffer
local framebuffer = CreateFramebuffer(window)

-- Create a camera
local camera = CreateCamera(world)
camera:SetClearColor(0.125)
camera:SetPosition(0, 0, -4)

-- Create a light
local light = CreateBoxLight(world)
light:SetRotation(45, 35, 0)
light:SetRange(-10, 10)
light:SetColor(2)

-- Create a model
local model = CreateBox(world)
model:SetColor(0, 0, 1)

-- Main loop
while not window:Closed() and not window:KeyDown(KEY_ESCAPE) do
    model:Turn(0, 1, 0)
    world:Update()
    world:Render(framebuffer)
end

 

  • Like 3

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
23 minutes ago, Josh said:

Please examine these two examples carefully, and tell me which one feels better to you?

Procedural

--Get the displays
local displays = GetDisplays()

-- Create a window
local window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[1], WINDOW_CENTER + WINDOW_TITLEBAR)

-- Create a world
local world = CreateWorld()

-- Create a framebuffer
local framebuffer = CreateFramebuffer(window)

-- Create a camera
local camera = CreateCamera(world)
SetCameraClearColor(camera, 0.125)
SetEntityPosition(camera, 0, 0, -2)

-- Create a light
local light = CreateBoxLight(world)
SetEntityRotation(light, 45, 35, 0)
SetLightRange(light, -10, 10)
SetEntityColor(light, 2)

-- Create a model
local model = CreateBox(world)
SetEntityColor(model, 0, 0, 1)

-- Main loop
while not WindowClosed(window) and not KeyDown(window, KEY_ESCAPE) do
    TurnEntity(model, 0, 1, 0, true)
    UpdateWorld(world)
    RenderWorld(world, framebuffer)
end

Object-oriented

--Get the displays
local displays = GetDisplays()

-- Create a window
local window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[1], WINDOW_CENTER + WINDOW_TITLEBAR)

-- Create a world
local world = CreateWorld()

-- Create a framebuffer
local framebuffer = CreateFramebuffer(window)

-- Create a camera
local camera = CreateCamera(world)
camera:SetClearColor(0.125)
camera:SetPosition(0, 0, -4)

-- Create a light
local light = CreateBoxLight(world)
light:SetRotation(45, 35, 0)
light:SetRange(-10, 10)
light:SetColor(2)

-- Create a model
local model = CreateBox(world)
model:SetColor(0, 0, 1)

-- Main loop
while not window:Closed() and not window:KeyDown(KEY_ESCAPE) do
    model:Turn(0, 1, 0)
    world:Update()
    world:Render(framebuffer)
end

 

Personally, I enjoy programming a lot more when using an object-oriented approach. It just feels more natural for me to think in terms of entities that have both behavior and state, especially when I'm working on larger projects or systems with many interacting parts—like a video game.

OOP helps me keep my code organized, scalable, and easier to maintain. I like being able to encapsulate logic, reuse functionality through inheritance, and structure things around how they relate and behave.

I do appreciate the procedural style and its simplicity for smaller or more direct tasks. But when I have the choice, OOP is definitely where I feel most comfortable and creative.

  • Like 2

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games

  • Josh changed the title to Lua API Design
Posted

Replies will be hidden, for now.I don't want to influence people's answers.

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

I asked my niece which one she liked better, and she chose the object / method style.

I've made good progress with Lua Language Server, so I think the matter is settled, in favor of the object/method API design.

Thanks everyone for your feedback.

  • Like 3
  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...