In the sweet spot between C & C++ there is the esoteric language NIM.
Drawbacks :
- Main developer has a difficult character.
- & No foundation. So companies don't welcome this language.
Good things :
- Class emulation
- Reference counting behaving like garbage collection
- Good libaries
https://nim-lang.org/docs/lib.html
Example of object orientation in NIM Language, code is self declarative.
---------------------------------------------------------------------------------------------------------------------------
Example of a QT6 application with callback functions :
cat test.nim
Script to install library & compile :
As you see this is rather easy & straightforward.
Drawbacks :
- Main developer has a difficult character.
- & No foundation. So companies don't welcome this language.
Good things :
- Class emulation
- Reference counting behaving like garbage collection
- Good libaries
https://nim-lang.org/docs/lib.html
Example of object orientation in NIM Language, code is self declarative.
Code:
type Warrior = object
name: string
hp: int
# "Constructor" - returns the object by value on the stack
proc newWarrior(name: string, hp: int): Warrior =
Warrior(name: name, hp: hp)
# Member function emulation
proc takeDamage(self: var Warrior, amount: int) =
self.hp -= amount
echo self.name, " took damage! HP is now: ", self.hp
# Usage
var hero = newWarrior("Arthur", 100) # Created on stack
hero.takeDamage(20) # Method syntax
---------------------------------------------------------------------------------------------------------------------------
Example of a QT6 application with callback functions :
cat test.nim
Code:
import std/strformat, seaqt/[qapplication, qpushbutton, qlineedit, qlabel, qvboxlayout, qwidget]
let
_ = QApplication.create()
window = QWidget.create()
layout = QVBoxLayout.create(window)
label = QLabel.create("Ready...")
edit = QLineEdit.create()
btn = QPushButton.create("Hello seaqt!")
layout.addWidget(label)
layout.addWidget(edit)
layout.addWidget(btn)
var counter = 0
btn.onPressed(
proc() {.closure.} =
counter += 1
btn.setText(&"Clicks: {counter}")
)
# Fix: Match the signature 'openArray[char]'
edit.onTextChanged(
proc(text: openArray[char]) {.closure.} =
# Convert openArray[char] to string for the label
label.setText("Input: " & $text)
)
window.setMinimumSize(320, 200)
window.show()
quit QApplication.exec().int
Script to install library & compile :
Code:
nimble install https://github.com/seaqt/nim-seaqt.git@#qt-6.4
nim cpp --run --passC:-fPIC ./test.nim
As you see this is rather easy & straightforward.