-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* done a lot of details and mainly zig and c interop * added comptime to index * added TODO why python so slow and changed the way I do a loop * last time i do a commit this big * small details * fixed what was asked * fixed small details * fixed details to green threads after hpc course
- Loading branch information
Showing
18 changed files
with
4,233 additions
and
1,544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docs/WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
* Case studies | ||
** Interacting with processuses | ||
TODO | ||
https://github.com/Pismice/rename-i3-workspace | ||
Was zig the good choice ? | ||
Was it easy ? | ||
What were the problems ? | ||
What libraries did i use ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#+bibliography: bibliography.bib | ||
|
||
** Code styles | ||
*** Style guide | ||
**** fmt | ||
First it is important to know that Zig comes with a formatter that you can use using: | ||
#+begin_src shell | ||
zig fmt file.zig | ||
#+end_src | ||
This util is going to enforce basic things for you like: | ||
- Indentation | ||
- Braces alignment | ||
- Line length | ||
- .... | ||
**** Naming conventions | ||
1. =TitleCaseTypeName=: for types and structs that are callable (for "classes" in other languages basically) | ||
2. =camelCaseFunctionName=: for functions | ||
3. =snake\_case\_variable_name=: for variables and everything else | ||
|
||
*** undefined and null values | ||
TODO for some reason the 2 org block code are not working, maybe i should "testsuite" | ||
TODO how can i make the second one print the error ? | ||
|
||
In Zig you can leave variables uninitialized, but you have to do that explicitly contrary to C where you can leave variables uninitialized and never truly notice it. Note that leaving the value undefined is going to leave the memory of this variable to some complete nonsense value (except in Debug mode where it will be [[https://github.com/ziglang/zig/issues/15603 | ||
][set to 0xaa]]) | ||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
const my_var: u8 = undefined; | ||
std.debug.print("my_var: {}\n", .{my_var}); | ||
#+end_src | ||
|
||
This is to be avoided as much as possible, if you have some in your code it might makes sense to use an Optional type instead so that compiler can scream at you :) | ||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
const my_var: ?u8 = null; | ||
|
||
// .? is syntaxic sugar for "orelse unreachable" which is going | ||
// unreachable is going to emit a panic (unable to unwrapp null) ! | ||
// THIS CODE WILL PANIC IF UNCOMMENTED | ||
// _ = my_var.?; | ||
|
||
// if value is "null" then "42" will be assigned | ||
const value: u8 = my_var orelse 42; | ||
|
||
// print 42 because value was null before | ||
std.debug.print("my_var = {}\n", .{value}); | ||
#+end_src | ||
|
||
#+RESULTS: | ||
|
||
*** Zen | ||
Zig encourages you to use the [[https://ziglang.org/documentation/0.12.0/#Zen][Zen philosophy]], they reflect well the spirit behind Zig, here they are: | ||
- Communicate intent precisely. | ||
- Edge cases matter. | ||
- Favor reading code over writing code. | ||
- Only one obvious way to do things. | ||
- Runtime crashes are better than bugs. | ||
- Compile errors are better than runtime crashes. | ||
- Incremental improvements. | ||
- Avoid local maximums. | ||
- Reduce the amount one must remember. | ||
- Focus on code rather than style. | ||
- Resource allocation may fail; resource deallocation must succeed. | ||
- Memory is a resource. | ||
- Together we serve the users. | ||
|
||
Sources: | ||
https://ziglang.org/documentation/master/#Type-Coercion-undefined | ||
https://nathancraddock.com/blog/zig-naming-conventions/o | ||
https://ziglang.org/documentation/master/#undefined | ||
https://ziglang.org/documentation/master/#Style-Guide | ||
https://github.com/ziglang/zig/blob/master/lib/std/fmt.zig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
** Compiler messages | ||
In a language that aims to report most of its issues at compilation time, it is important to have clear and concise error messages. However at the time we are writing this it is sadly not the case. Here are a few compiler messages that you might encounter that are very hard to understand: | ||
|
||
*** Trying to print without the correct struct syntax | ||
We are going to start with the most basic one, everyone doing Zig did at least one time | ||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
std.debug.print("Hello I am {} years old", 12); | ||
#+end_src | ||
|
||
#+begin_example | ||
/home/tetratrux/.zvm/0.11.0/lib/std/fmt.zig:87:9: error: expected tuple or struct argument, found comptime_int | ||
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType)); | ||
#+end_example | ||
|
||
Is the type of error you should get, from reading that we cant even know from where the problem is in our code, no line number, no stacktrace, nothing. | ||
|
||
But if you read the message carefully and you know that [[https://ziglang.org/documentation/master/std/#std.debug.print][print]] second argument except a struct with the *.{}* syntax, you realize that you passed a value with the wrong type. | ||
|
||
So when you get that type of error message make sure that you are printing your message correctly with the second argument that should be a struct with the *.{}* syntax. | ||
|
||
#+begin_src zig :imports '(std) :main 'yes :testsuite 'no | ||
std.debug.print("Hello I am {} years old", .{12}); | ||
#+end_src | ||
|
||
This is an [[https://github.com/ziglang/zig/issues/19158][ongoing issue]] by the time I am writing this in 0.12.0 | ||
|
Oops, something went wrong.