My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Journey so far with the Blade programming language

Ore Richard Muyiwa's photo
Ore Richard Muyiwa
·Mar 4, 2021·

3 min read

Journey so far with the Blade programming language

Hi guys!

This is going to be my first hashnode post and the first of a series of posts in which I will be carrying you guys along the development of my programming language - Blade as well as it's interpreter.

First and foremost, What is Blade??

Blade is an open-source interpreted general-purpose programming language with a focus on simplicity, cleanliness and capacity and encourages a focus on algorithm over syntax. Blade is a C derivative that targets to allow developers to write simple code but do very powerful stuffs.

Blade is still in very active and rigorous development and has taken a lot of inspiration from projects such as Dart, JavaScript, Python, Lua and a few other languages and for now has a few test suites in it's repository and nearly no documentation. Though it's extreme similarity to JavaScript and Dart makes it easy to grasp even from the sample tests and the few libraries it has now.

Documentation has began, and will soon get it's own repository.

Blade is Turing complete and already supports the following features:

  1. Conditionals (if statements)
  2. Loops (for loops, iter loops, while loops)
  3. Using statements (similar to switch statement in Java and C)
  4. Functions
  5. Classes
  6. Inheritance
  7. Static methods and fields
  8. Lists and dictionaries
  9. Byte manipulation
  10. File manipulation
  11. A few libraries such as math, time, io and os that enables a lot of powerful code already
  12. Exceptions
  13. A REPL
  14. And many more... (please feel free to explore the repo)

There are many things I have skipped here!

A simple taste of Blade:

def fib(n) {
  if n < 2 return n
  return fib(n - 2) + fib(n - 1)
}

def fib2(n) {
  if n < 2 return n

  var i = 1, previous = 0, pprevious = 1, current

  while i <= n {
    current = pprevious + previous
    pprevious = previous
    previous = current
    i++
  }

  return current
}

class A {
  to_abs() {
    return 300
  }

  to_string() {
    return 'A class called A'
  }
}

echo abs(-10)
echo abs(A())
echo to_string([1, 2, 3])
echo to_string({name: 'Richard', age: 28})
echo to_string(A())

var start = time()
echo fib(40)
echo 'Time taken for recursive fibonacci: ${time() - start}s'

start = time()
echo fib2(60)
echo 'Time taken for non-recursive fibonacci: ${time() - start}s'

Sample output:

10
300
[1, 2, 3]
{name: Richard, age: 28}
A class called A
9227465
Time taken for recursive fibonacci: 2.104601860046387s
1548008755920
Time taken for non-recursive fibonacci: 1.001358032226562e-05s

Blade is pretty fast!

Feel free to checkout the repo on Github and collaborate as well.

I'll be updating you as we continue until we reach the 10th stable production release (that's a lot of years from now I hope).

Feedbacks are welcomed!

Till next time...