Monday, 31 August 2020

Flock, Day 2

So I decided to rebuild LLVM following the instructions, it's taking a while to rebuild, but I think its better this way as LLVM version 10.0.1 has come out and the windows version needs a source build. I appear to of made a couple of errors in my first built.

  • Using the cmake gui, made life a lot easier, (although I had to learn the tool)
  • Ensuring the install and build directories don't have whitespace in the path also seemed to make a difference. If at first you don't succeed read the instructions, as my dad says. Although in my case, read the instructions more thoroughly.

So I think I want to cover some thoughts on syntax, in particular how we deal with removing Null/Nil.


I don't want nulls to be in the language. I could just insist all variables gets instantiated, and throw an exception if they aren't. However this is a pain as a developer, as often forcing instantiation, makes for some awkward code with a significant amount of error handling. 

The typical approach in languages and APIs is to specify an Option(al) variable, one that is either set or not. So your variable effectively wraps the instantiated one. If the instantiated version doesn't exist it is represented by 'None'. if it does it is represented by the wrapped variable, like 'Some' or 'Any'. Rust does this particularly well, by representing the 2 states as an enum. 

There is still some exposition style bagage here, in java you would call isPresent() or in Rust use some form of deconstruction, often you stick this logic into a switch, match or if statement. Which brings me to the use of syntax.

A common way to infer this logic is via the Elvis operator ?: this basically says, if not present default to the next bit. Alteratively ?. Says if present do the next bit, otherwise stop. This is definitely the way to go, and this short hand is top of my list. I would like to add some other syntactic sugar here for conformity. Additionally since we are a reactive language, being able to syntactically support errors is also quite useful, now using ! could also mean there is a problem, and we would use it a bit like onerror, or the catch, so maybe :! Defaults as on error, and .! Continue if no error. However we also use ! in logic statements, so this could get confusing. So I need to spend some time thinking about the cleanest way of differentiating.

You might at this point go 'doesn't this fly in the face of the rule to be symbol minimalist?' My answer 'Um.... yes, but I also want it to be easy.' Part of making a language is having to decide what feature is more important, and because its my language (for the moment) I get to make that choice.


It looks like it has just finished building, but family have returned and I have a dishwasher door to replace, the time just creeps away!


Friday, 28 August 2020

Flock, Day 1, Version 0.0.0

Ok.....
Right....
If....

Its been about 6 months since I decided to write my own programming language. Although admittedly I have been wanting to do this for at least 15 years. I really wish I had the desire 5 years prior, then I might of actually studied some compilers at university. 

No matter, everyone thinks I am mad for attempting this, I get questions like what makes your language so special? I struggle to answer this, not because I don't think it will have anything special to offer, but generally the concept is such a wide one to sum up. 

I am a software engineer, who for years specialised in Java along the way I picked up another 10 or so programming languages and all of them wound me up. The following paragraphs is intentionally meant to ensure none of them want to invite me round for dinner.

Language designers sit in several camps:

In camp one: the deeply technical mathematicians that wouldn't know an antipattern if it bit them on the behind, they provide language constructs a day to day developer would never use. Writing code in these languages requires a ridiculous amount of time in a debugger looking for memory leaks, and code that is so verbose in order to return a simple variable, that frankly I am surprised they aren't considered a health risk due to the inevitability of carpal tunnel syndrome. I include languages like any of the C variant languages. The more characters added to the name of the C variant language the worse it gets.

In camp two: the more deeply technical computer scientists, that think the tower of hanoi problem is one worth solving in the most obtuse way possible. I include any language that includes the word log in the title.

In camp three: we have the purists who believe Object Orientation or functional programming is the only way to go. Developers, with jobs generally want to fix problems and go home, not spend a lifetime trying to break your language to get it to do something practical.

In camp four: we have morons like me who want to make a practical everyday language, most are doomed to fail. However these 'morons' occasionally look at the other 3 groups with envy, and do stupid things, like introduce lifetime semantics, or decide that in getting rid of memory allocation and deallocation, expecting a developer to care about which memory model to use is solving a problem. I am looking at you Rust. I think James Gosling knows what I am talking about.

I want to be in camp 4, but my main goal is to be pragmatic wherever possible. The following is my 10'000 ft view. This view will change, I am if anything, chaotic by nature.

  • No Garbage collector, With support for object graphs (over object trees) inspired by rust
  • Flow executions, i.e. Parallelisation without explicit threading. inspired by projectreactor.io
  • A clear distinction between what I am (Structs) and what I do (Traits)
  • Object Orientated
  • Functional
  • Strongly Typed
  • Symbol minimalist (i.e. keeping down on the number of different symbols)
  • Clearly Structured, (i.e. not perl)
  • Pointer free (no &**mayvar)
  • Convention orientated, (i.e. if most programming languages have a convention, follow that convention)
  • Operator overloading, whilst retaining clarity (tough one)
  • no lifetime semantics,
  • Machine sympathetic, (Smart resource management)
  • Fully compiled
  • Support for Dependency Injection
  • Support for Aspect Orientated Programming
  • Support for Testing (including spec by example, such as cucumber)
  • Null free
  • Extensible
  • Fast
You might look at this and think 'some of this is just library stuff' yes you are right, I am not at the point of making that distinction.

So what is my USP, there are a few, I think the biggest one for most, will be my attempt to move away from the concepts of threads to the concept of flows of execution, they sound the same. We use threads on the whole for one thing, and that is to parallelize tasks, to ensure that doing one thing doesn't block another from doing its job. What if, you don't have to care, every unit of work by its very nature is paralizable, that your software will make the best use of the resources available to it. There is a lot to work out, how do we identify blocking code, how do we identify parallelizable work, how do we not freeze the machine by over-utilizing underlying system threads to so the work.

Anyway
  • Task 1: work out how you are going to compile this -> Answer lets try LLVM.
  • Task 2: install LLVM on my windows machine, (I am not kidding you, this took 3 evenings!)
  • Task 3: Shit I am going to have to remember c++, std::move... oh come on!
  • Task 4: read the API docs for LLVM IR, where the fuck are the bits about threads.
  • Task 5: read the tutorial, ok maybe we can do this, you have written parsers before.
  • Task 6: read the tutorial again. I think you are procrastinating.
  • Task 7: Write a blog....

More (Maybe) to come.

P.S.
Flock stands for Flow and Fork, the 2 things it does for you. Now I know rk and ck don't match, but maybe I had another word in mind.

Flock Day 8

 It's been a very long time since I last posted, although I have been spending on average 2-3 hours a day cutting code since the last po...