<_Vi>
What variable naming scheme is supposed to be used in Zig to simulate shadowing? `var x = ...; var x2 = ...; var x3 = ...;` or `var x = ...; var x_ = ...; var x__= ...;`?
<andrewrk>
is this an abstract question or do you have an actual use case?
<andrewrk>
this is not an issue
<andrewrk>
I don't mean to be rude, I mean that I have written a lot of zig code and this has not been an issue in practice
<fengb>
It can be a little hard to pick up
<_Vi>
For example, in first part of a function someting is `?T`. Then it is established that it is not `null`, and the rest of the function continue with the same thing, but in non-optional form.
<andrewrk>
call it opt_thing and then you can use thing if it's not null
<_Vi>
Means prefixing identifier with type-related things?
<andrewrk>
not necessarily. I don't think these abstract questions are going to have satisfying answers
<_Vi>
E.g. something starts as "ptr_opt_widget", then it later it is "opt_widget" and finally "widget". Later "cloned_widget"...
<andrewrk>
I sincerely, honestly do not see a problem here
<_Vi>
Is there a code style document for Zig?
<Tetralux>
_Vi: That instance, there's a pattern of `var thing = opt_thing orelse ...;`
<_Vi>
"stdcallcc" -> Why calling conventions are keywords? If new calling convention gets added late, does that mean new keyword will be added (invalidating identifiers)?
laaron has quit [Remote host closed the connection]
waleee-cl has quit [Quit: Connection closed for inactivity]
<stratact>
andrewrk: I think the Azure CIs in my PR are stuck in a loop waiting for the next avaliable agents. It's been going on for 45 minutes now, how can I reset them?
<mikdusan>
wow i just realized enum supports bound functions
<Tetralux>
Yeah - I had a moment of wondering that a while back and tried it xD
<andrewrk>
stratact, the CI is for me, not you :P test locally
<andrewrk>
the point of the CI is so that I don't have to ask people whether they tested locally, it just does the testing
<stratact>
I realized that a couple of hours ago since that was the point of my 2nd PR and fair enough. Other than the need to merge std/fs_ext.zig into std/fs.zig, I want to know what other kinds of things I should clean up or do to enhance the work, if need be.
dingenskirchen1 has joined #zig
dingenskirchen has quit [Ping timeout: 276 seconds]
dingenskirchen1 is now known as dingenskirchen
<mikdusan>
Tetralux: using enums like that. such a perfect place for conversions and mapping functions. it's things like this i love about zig
<stratact>
How come `==` is not allow for []const u8?
brodeuralexis has joined #zig
<fengb>
Probably because it’s ambiguous whether you want to compare the pointer or do a memcpy
<Tetralux>
More likely that it's slow.
<Tetralux>
I don't know about anyone else, but I've _never_ wanted to compare the ptrs of two slices with ==.
<Tetralux>
I'd do a.ptr == b.ptr.
<Tetralux>
I have found myself wanting to == slices though.
<fengb>
But it also doesn’t overload operators
<fengb>
So the only non overloaded behavior is pointer + len check (pretend it’s a struct)
<fengb>
But that’s probably not what you want
<brodeuralexis>
Is there any way to obtain generic information of structs at comptime ?
<brodeuralexis>
Supposing I have `Matrix(usize, usize, T)`, can I have something like `fn matrix_add(a: Matrix(infer N, infer M, infer T), b: Matrix(N, M, T)) Matrix(N, M, T)` ?
<Tetralux>
Only by passing comptime T: type
<Tetralux>
And then b at the rettype is T
<Tetralux>
But yeah that would be nice.
<Tetralux>
Honestly I'd like that.
<brodeuralexis>
I came upon this problem trying to implement some linear algebra data structures and wanted the help of the type system to catch bugs.
<brodeuralexis>
Heck, you could replace `infer T` with `var T`, so no new keyword gets added.
<Tetralux>
For reference, Odin does this with `matrix_add(a: $MATRIX/Matrix($N, $M, $T), b: MATRIX) MATRIX` IIRC.
<Tetralux>
In the body, MATRIX is the matrix type, and M, N, T are the type parameters to Matrix.
<brodeuralexis>
Though I understand Odin's syntax, I can't explain why I do not like it :P
<Tetralux>
I like that you don't have to think about the type before you type it.
<Tetralux>
You just write it out.
<Tetralux>
I want a generic type, so long as its a Matrix, with type params N, M, and T -- oh and also return a value of that same type.
<Tetralux>
It flows quite well.
chemist69 has quit [Ping timeout: 246 seconds]
<Tetralux>
I also like that the main difference between it and the normal case is that you have the '$'.
<Tetralux>
I find it quite elegant.
<brodeuralexis>
Now I think I like it a little more ;)
<mq32>
Pwipwi, which version of zig are you using?
<Pwipwi>
0.4
<Pwipwi>
when I remove export, it compiles
<Pwipwi>
but I need it exported
kristoff_it has quit [Remote host closed the connection]
_Vi has quit [Ping timeout: 245 seconds]
<mq32>
you should use the current master branch
<mq32>
(precompiled on the website)
<mq32>
it is much improved over 0.4
<Pwipwi>
ok effectively, that works
<Pwipwi>
well, it compiles at least :)
<Pwipwi>
it however still doesn't do what I want. :(
<Pwipwi>
bonus question : is it possible at all to do a relative import of a c header ?
<mq32>
what do you want to achieve?
<Pwipwi>
I want to write a nodejs extension using zig
<Pwipwi>
I'm managing to create a dynamic library, but I can't seem to have the module "self-register", which it seems to do by having the `napi_module_register()` function called at library load time
<Pwipwi>
so I created a function that does exactly that, which I intend to call when my library loads, but no dice.
<Pwipwi>
is it possible to link against libc on the command line ?
<Pwipwi>
(I'm trying to do a printf for debugging)
<mq32>
but you can also print with std.debug.warn()
<Pwipwi>
--library c, found that
laaron has joined #zig
kristoff_it has joined #zig
<Pwipwi>
if I do a std.debug.warn, should it display something if I am in a terminal ? No matter how it is called
<Pwipwi>
?
<Pwipwi>
ok sorry for the constant spam, anyway I managed to have my function called. It would seem that calling my function something else than "init_module" did actually work
<Pwipwi>
I have *no idea* why that is
<mq32>
do you have extern calling convention of your function?
<mq32>
if you want to call it in .init_array
<Pwipwi>
I suppose c if that makes any sense
<mq32>
yeah, c calling convention
<Pwipwi>
I still don't get why the name would be an issue
<mq32>
it should not be the name, but the calling convention that will change
<Pwipwi>
I declared them the same, with a plain extern
<mq32>
how is Fn declared in your example?
<Pwipwi>
const Fn = extern fn () void; ?
<Pwipwi>
I then have a `export fn _register_my_module() void {`
<Pwipwi>
which ceases working whenever I rename it as init_module
<Pwipwi>
... maybe there is a symbol that I'm shadowing if I do so ?
<mq32>
huh, weird
donpdonp has quit [Read error: Connection reset by peer]
donpdonp has joined #zig
<Pwipwi>
IT WORKS
<Pwipwi>
I DID IT YAY ME
* mq32
claps!
<Pwipwi>
by the way, I did it all by going into `node_api.h`, which is laden with macros everywhere which they want you to use
<Pwipwi>
I suppose there is no way of calling those from zig ?
<Pwipwi>
(I just created the objects and called the functions)
<Pwipwi>
is there a way to dump the result of a .h file interpretation by zig ?
<mq32>
i think it's somewhere in the zig-cache directory
<Pwipwi>
oh, I suppose then that it's not zig code
<Pwipwi>
oh it is
<mq32>
i'm interested in how well my small C library will translate to zig
<Pwipwi>
well so far it's pleasantly surprising
meheleventyone has joined #zig
<Pwipwi>
how do I add an include path ?
<Pwipwi>
so far I've been putting the complete path to my header
<mq32>
-I i think
<mq32>
-isystem [dir] add additional search path for other .h files
<Pwipwi>
ah I grepped include, missed that
<Pwipwi>
say mq32, how far do you think zig is from having an functioning stage 2 compiler with auto complete support ?
<Pwipwi>
a*
<mq32>
i have no idea
<mq32>
i think it's still a big pile of work
<Pwipwi>
I'm kinda grokking the idea of doing a temporary one in javascript for vscode
<Pwipwi>
I really miss having autocomplete
<daurnimator>
Pwipwi: have you tried tabnine?
<Pwipwi>
no, never heard of it
<Pwipwi>
is it any good ?
<daurnimator>
yeah its sort of scarily good
<Pwipwi>
with zig even ?
<Pwipwi>
« Nonetheless, there are some situations where you would rather use a semantic completer than TabNine. For example, if you don’t know what methods are contained in the class Math, you could type Math.and see what suggestions are provided by the semantic completer. »
<Pwipwi>
unfortunately that's precisely my use case :D
<bgiannan>
daurnimator, that's not safe as i mean it then, just more useful for the developer
<fengb>
It just muddles it. The zig one has awkward nesting but it’s a lot more readable
<bgiannan>
fengb, what are you thoughts on swift's optional chaining?
laaron has quit [Client Quit]
<fengb>
Eh... it’s always bothered me since ObjC
<bgiannan>
daurnimator, in Swift I avoid `!` (which is `.?` equivalent) because it inevitably leads to nil-unwrapping in production because somebody used it wrong or moved code using it
<fengb>
I’d prefer a different operator
laaron has joined #zig
<bgiannan>
daurnimator, i actually set up our linter to block compilation if `!` is not used in a few whitelisted cases
<fengb>
I guess my beef with Swift is that it uses a let, 2 assignments, a comparison, and finally a block. It looks like it’s trying to do 3 different things as one giant statement
<ceymard>
hello everyone, does anyone know how can I supply a function linked to a struct as a callback ?
<fengb>
It works, but it looks like it’s just kludged together
<bgiannan>
fair enough but i think it's needed for the few reasons i just described
<mq32>
hey
<mq32>
fengb, how would you solve the following problem:
<mq32>
i have an API that has an internal message reception system
<mq32>
now if the user of the API wants to access the messages, i could provide the following:
<mq32>
SDL-Style Event pumping (You poll for every single event and get a struct pointer=
<mq32>
or i make it callback based which would make memory management easier (callback receives memory,but does not own it)
<mq32>
right now, i'm more towards the second option, as it makes memory management more easy, but i think about how the callback(s) are designed
<mq32>
one callback per event type or one callback for all events accumulated
<fengb>
Whenever I hear callback, I would think async could be better :P
<mq32>
pure C api doesn't support async ;)
<fengb>
So I’m Go, I’d use a channel
<fengb>
Oh
<mq32>
i don't want any dependencies to language features like async/channels
<daurnimator>
mq32: always "pull" and provide notifications
<mq32>
daurnimator, can you elaborate that?
<mq32>
right now, my API is this:
<daurnimator>
mq32: i.e. your api should have a `give_me_some(&output_buffer, max_items)` and a `give_me_a_filedescriptor_that_will_poll_readable_when_you_have_some()`
<daurnimator>
mq32: though that's not super helpful
<fengb>
fieldParentPtr still depends on a pointer reference inside the struct
<ceymard>
oh, that's pretty sweet
<ceymard>
I saw mentionned on the archives that someone made a closure-like thing at comptime
<ceymard>
I'd like to see code where functions are dynamically generated
<fengb>
Allocators are the best example in std
laaron has joined #zig
<ceymard>
fengb: right, so this doesn't help me after all since I don't have the field's address but the function's
laaron has quit [Client Quit]
<fengb>
Functions in Zig are like C. They’re always global and statically defined
<fengb>
Er... not always global but definitely static memory
<ceymard>
so I can't wrap a function of a given type to transform its arguments and call another one
<mq32>
daurnimator, i think i will go with the pump(callback) method, this will make both using and implementing the library simple
<fengb>
So you need to manually pass in a pointer reference
<daurnimator>
mq32: callbacks are always fraught with danger..
laaron has joined #zig
<daurnimator>
mq32: unless you are super super high performance; just use a pull model and use the heap where you need...
<ceymard>
I'll try to describe better what I mean ; in a library I'm using, a function expects a function pointer as an argument. The passed function expects certain arguments of certain types. I find it a chore to deal with those types. So I'd rather have them transformed into other types and call another function that handle the nice types.
<mq32>
daurnimator, in what way are callbacks fraught with danger?
<ceymard>
And I'd like to do so rather transparently.
<ceymard>
but it seems that there's no solution for me. :)
<daurnimator>
mq32: e.g. what if I want the lifetime of the argument you give me to outlive my callback invocation
<mq32>
then you are free to do the copy yourself
<daurnimator>
mq32: also things around indicating errors; long jumping out; potentially needing to go back to the mainloop (e.g. if I need to prompt the user for a decision)
<daurnimator>
mq32: can I then stop the pumping somehow?
<daurnimator>
(to let me handle this event without proceeding to the next item?)
<daurnimator>
not to mention issues around threading.... e.g. will my callback always be called in the current thread?
<fengb>
ceymard: I think what you need is a function allocated in process memory, which doesn’t exist yet. There’s a proposal for closures but nothing concrete
<ceymard>
I thought so
<mq32>
yeah exactly that is the reason why i started this discussion ;) get some input on implementation styles
<daurnimator>
(where the "current thread" is the one where I called pump?)
<mq32>
that's what i have the pump function for
<mq32>
you invoke the function in the thread you want to process your callbacks
<daurnimator>
mq32: do you pump one or many?
<mq32>
yet deciding on it
<mq32>
probably only one
<ceymard>
is it possible to extend a type with functions in another module ?
<daurnimator>
pumping one is usually pretty bad for performance. pumping many is usually bad for developer experience.
<mq32>
(time) performance isn't a thing i care about at this point
<ceymard>
for instance, I get a struct from this c library. Can I add functions to it so that I can call it message-style without messing with the underlying type ?
<mq32>
event density is about "1 / second"
<daurnimator>
mq32: then use the heap as I recommended earlier....
<mq32>
heap hurts me more than time
<mq32>
a lot more (i plan to do embedded, so only 32k Heap)
<mq32>
where parts of the message are already on the heap
<mq32>
so i cannot duplicate stuff just to make a nicer API
<mq32>
at best, the whole library is zero-alloc inside
<ceymard>
how can I remove the optional part of a type ?
<ceymard>
rather, is it normal that the compiler does not accept to assign a non optional variable to an optional field of the same type ?
laaron has joined #zig
<mq32>
re
<ceymard>
ok nevermind I was doing multiple c imports of the same file which of course messed things up
<ceymard>
and I found that @typeInfo(my_type).Optional.child did what I wanted in the first place
<Tetralux>
mq32: Why not just have a message struct instance somewhere which gets used for returning the message, but will be overwritten by a call to pump; then if the user wants to keep the message around they copy it.
<Tetralux>
.. otherwise you just reuse the same struct instance all the time.
<mq32>
yeah, this will work for known-size messages
<Tetralux>
I mean, messages are always of known maximum length right?
<Tetralux>
If they were >32K, you'd already break.
Hirezias has joined #zig
<Tetralux>
If you know all messages are <512 bytes, you could just set aside a buffer of that size.
<Tetralux>
You'd then return a ptr to it from pump
<Tetralux>
If it's null, no more messages yet.
<mq32>
Tetralux, yeah, but i have user-input in those messages
<mq32>
so messages may be a whole text document ^^
<Tetralux>
I mean, you already will be forced to truncate or error if their message is too long.
<Tetralux>
Enforce that and limit it, or have a built-in way for the payload to be spread over multiple messages.
<mq32>
yes, but i would really like to prevent having any message twice in RAM
<mq32>
but i got an idea how i can uncouple the library better
<mq32>
push-semantic, but with inversion-of-control
<Tetralux>
I'd definitely go with `while (pump()) |msg_ptr| {}` for getting them
laaron has quit [Remote host closed the connection]
<Tetralux>
I'm not sure what inversion of control means here xD
<mq32>
you provide the library with the actual message contents :D
<mq32>
instead of making something in the library pull the messages
<Tetralux>
Seems ideal.
<mq32>
yeah
<mq32>
having a walk solves IT problems quite good :D
<Hirezias>
Hello, I have a sample of code wich results in segfault and probably would'nt even compile : https://pastebin.com/peLUwG6g
<fengb>
It shouldn't compile. ".value = [1]u8{'a'}" shoved a []const u8 into a []u8
<fengb>
You're reassigning static string data in this case
<Hirezias>
My intuition is that the array in wich t has its slice is in read only memory, as a constant, even if its type is mutable.
<Hirezias>
:)
<fengb>
Yep
<fengb>
Need to assign the underlying .value array an actual var
<fgenesis>
hoooly crap golbolting this example turns out as a lot of code
knebulae has quit [Read error: Connection reset by peer]
<Hirezias>
Something strange with zig for me is that when you do const a: u32 = 3; and var b: u32 = 3; the types of a and be are the same (equality of @typeOf returns true).
<fengb>
0.4.0 errors out correctly
<fengb>
So there's been a regression :/
<Tetralux>
Anyone else able to build with master right now?
<Tetralux>
Only it looks like it wants to find llvm-config but it doesn't seem to be in the LLVM release binary now?
<Tetralux>
Hmm.
<Tetralux>
Looks like you have to get the version from "Building Zig on Windows" - it's not clear to me why.
waleee-cl has joined #zig
halosghost has joined #zig
alexander92 has joined #zig
Tetralux has quit [Read error: Connection reset by peer]
laaron has joined #zig
Tetralux has joined #zig
hspak has quit [Ping timeout: 244 seconds]
Akuli has joined #zig
laaron has quit [Remote host closed the connection]
<_Vi>
"place bets on whether #3260 will pass CI on 1st try" -> Looks like my pessimistic guess was wrong.
<ceymard>
how can I have the equivalent of a void* pointer ?
<_Vi>
For learning Zig, is it better to update to new LLVM9-based nightly from downloads or stay with older version for a bit?
<_Vi>
ceymard, `*c_void`?
<ceymard>
_Vi : "unknown-length pointer to opaque" comes up a lot in compilation errors
return0e_ has joined #zig
<ceymard>
when I use that
<mq32>
ah yeah
<_Vi>
ceymard, What do you want to use `void*`-like pointer for?
<mq32>
you cannot use a c-style pointer to an opaque type
<mq32>
just use a "normal" pointer to that type
<ceymard>
I don't know this type in advance
<ceymard>
I'm interacting with a C library which gives me void* pointers
<_Vi>
Are there plans to make distributed enumeration mechanism that is currently used for errors to be available for other purposes?
<ceymard>
I'm crashing zig a lot
return0e has joined #zig
return0e_ has quit [Ping timeout: 276 seconds]
<ceymard>
amazingly, it works
<ceymard>
I have barely any idea of what I'm doing
<ceymard>
and it does what I want it to do
<ceymard>
what a wonderful feeling
<_Vi>
ceymard, That feeling can be deceptive: security vulnerabilities are created this way.
<fengb>
Zig shouldn’t be crashing that much :(
knebulae has joined #zig
<ceymard>
fengb: I suppose not
<ceymard>
but I guess when the compiler starts spouting a bunch of nonsense onto my screen, it means it crashed ?
<ceymard>
have had that a couple of times already
<ceymard>
_Vi: certainly, but I don't care about them that much while I'm learning how to use this thing :)
<fengb>
Oh I'm not doubting you. Stability has been a bit spotty since the latest features
<_Vi>
fengb, Does it also output binary memory content on stderr on crashes for you?
<fengb>
I haven't seen it but it's been an issue in this channel :/
<_Vi>
Shall there be proper crash handler for Zig compiler, with customized message with invitation to create an issue?
<andrewrk>
today is the first I've ever heard of this binary memory content thing
<fgenesis>
andrewrk: someone posted a paste with binary "error message" 1-2 days ago too
<andrewrk>
hmmmmmm
<Tetralux>
Random thought: anyone thought of having successdefer, as it were?
avoidr has joined #zig
<andrewrk>
D thought of it. I don't think it's warranted
<mq32>
Tetralux, any usecase?
<Tetralux>
I didn't make a note of any of the ones I've come across unfortunately.
<Tetralux>
But it's essentially the same usecase as errdefer.
<Tetralux>
Except, obviously the opposite.
<Tetralux>
I want something to happen, but only if we return without error.
<Tetralux>
I cannot currently express that.
<Tetralux>
At least with just deferring.
<Tetralux>
More importantly, "something must happen upon return, but not if there's an error"
<fgenesis>
"defer [on error|succes|...] <expr>
<Tetralux>
[err|ok]defer <expr>
<mq32>
"ok ~~google~~ defer, order me a pizza!"
<Tetralux>
I'm not sure what that would do, but that would be amazingly cool.
<andrewrk>
it feels like everybody is thinking of new features to add, while I'm trying to think about what features we can remove
* Tetralux
grins
<Tetralux>
Incidentally, should using 'var v = ...' be faster than 'const v = ...' --- is that expected?
meheleventyone has joined #zig
<Tetralux>
Only it seems like it in my test case.
<halosghost>
interesting
<halosghost>
I wouldn't think so
<halosghost>
but I'm still on the periphery of this language's dev :)
<andrewrk>
const is always better
<Tetralux>
I tend to always use var because I don't wanna go back and make the things I want mutable, mutable.
<Tetralux>
I usually do that as a final pass.
<Tetralux>
If at all.
<andrewrk>
you're gonna have a hell of a time upgrading your code base when #224 is implemented
<Tetralux>
If you do that, I might stop using Zig.
<Tetralux>
Fair warning.
<Tetralux>
Well - 'stop' is a strong word.
<Tetralux>
But I will dislike that change quite a lot.
<Tetralux>
I'd rather you renamed const to let.
<_Vi>
andrewrk, "today is the first I've ever heard of this binary memory content thing" -> It is also visible in the new issues I recently filed.
<Tetralux>
That's still a tad painful to type, but still easier than const.
<companion_cube>
wow, an error, not a warning?
<fgenesis>
re: #224, better would be to have a warning instead of an error
<Tetralux>
Truthfully, I'd rather Zig just automatically turned all variables that are not mutated to be const automatically.
<fgenesis>
+1 Tetralux
<_Vi>
Are there ignorable errors in Zig (which you can selectively mute)?
<andrewrk>
no, zig has only errors
<companion_cube>
just turn`const` into `let`, and `var` into `mutable_variable`
<mq32>
andrewrk, brainfart on #224: make debug builds allow var when const would be possible as well. don't know if this just encourages people to deploy debug builds
<companion_cube>
you'll see what people use by default 😇
<andrewrk>
companion_cube, yeah that's not a bad idea
<_Vi>
Lack of warnings and treating "code cleanness" issues as errors feels to golang-ish.
<_Vi>
*too
<mq32>
because most of the code i write like "var x = /* initial value i will calculate later */" and then code stuff that depends on x
<stratact>
I agree, something like #224 could warn rather than error
<andrewrk>
the only reason #224 isn't already implemented is that it's tricky to detect correctly because of comptime branches
<fgenesis>
imo #224 is a handrince to iteration and development. it's ok for final code, but not while developing and testing
<mq32>
what fgenesis just said
<_Vi>
Such nitpicky errors also do not play well with generics / generated code.
<fgenesis>
*hindrance
<Tetralux>
+100 fgensis.
<fgenesis>
_Vi, totally this
<_Vi>
The "unreachable code" error is also a problem.
<companion_cube>
not sure why it's a problem for generics
<fgenesis>
oh gosh how much i hated that error when i was doing java
<Tetralux>
Making a non-changing variable to const is an optimization at best - and in the example I have in front of me it seems like a slight hinderance.
<fgenesis>
(in java, unreachable code is an error)
<_Vi>
There should be [at least] two classes of problems with code. One of the classes should be ignorable on various scopes.
<Tetralux>
On my branch for iterator removal procedures for ArrayList, this simple testing code shows a degradation between using const and non-const.
<_Vi>
Ultimately such errors may end up telling you: "error: your code is too abstract. Keep it simpler, not everybody is as smart as you."
<_Vi>
I prefer Zig to be Rust, but more direct, explicit and low-level; not Golang, but more direct, explicit and lowlevel.
<fgenesis>
what about if(comptime ... -> false) {code}
<fgenesis>
does this count as unreachable code?
<fgenesis>
i mean anything that's in an if but that turns out false at compile time
<mq32>
_Vi, i hope zig never gets to be Rust :D
<andrewrk>
if you like where zig is at now, you'll probably like where it's going. it's not going to be fundamentally different in the future
<mq32>
andrewrk, i hope so!
<companion_cube>
rust without traits or borrow checking would be perfect :P
<halosghost>
andrewrk: I definitely like many of your architectural decisions
<andrewrk>
I'm aware of the issues with refactoring and development/iteration, and I've used go & rust for non trivial projects
<fgenesis>
andrewrk: in any case, don't be like the C++-committee and actually listen to your users :P
<andrewrk>
just a reminder though, zig has always prioritized the time of people reading code over the time of people writing code. that does give license for annoying errors, if it means that you can be confident of more assumptions when reading code. that's the reason for no variable shadowing, for example
<andrewrk>
knowing that all variables are either const, or mutated, is a pretty useful thing to be able to rely on when reading a large codebase
<andrewrk>
writing code is O(1), reading code is O(N), where N is people
<fgenesis>
but if writing code is too hard nobody will do it
<_Vi>
andrewrk, Generics/codegen sometimes mean that the code is difficult in any case.
<andrewrk>
fgenesis, of course, there is a balance
<_Vi>
For #224 (unused `var`-ness): it also means that you need to change `var` to `const` when commenting out code, then back after uncommenting.
<_Vi>
At this rate unused `consts xxx = @import...` may also become an error.
<fgenesis>
same goes for an "unrachable code" when temporarily disabling a function by slapping a return near the top
<_Vi>
On of solutions is lax "dev mode" builds and stricter "publish mode" builds.
<_Vi>
For example, I typically use `#[allow(unused)]` when develop code in Rust, but remove it at some point when it matures.
<fgenesis>
all of these things are candidates that belong in a dev mode, exactly what _Vi said
<fgenesis>
i mean even LaTeX has \sloppy :D
<_Vi>
This turns off nagging of all sorts of unused things: unused imports, vars, non-constness, parameters, unhandled errors, etc.
<fgenesis>
or maybe a dev mode should be the default, because new people use defaults, and nothing else
<_Vi>
Mere enabling of such mode may emit compiler warning (so that one would want to turn it off, not just live with it forever).
<fgenesis>
so extra strict-ness as opt-in seems like the right way to do it
<andrewrk>
I'm closing IRC to fix bugs
<fgenesis>
yay bugs
<mq32>
andrewrk, sounds reasonable!
<_Vi>
fgenesis, "dev mode should be the default" -> not sure. There should be incentive to turn if off eventually.
<companion_cube>
isn't --debug already kind of a dev mode though?
<_Vi>
For example, Zig package central (when it exists), should not accept devmode-only code.
<_Vi>
companion_cube, All of `--release-fast`, `--release-safe` and `--release-small` should work with `--sloppy` as well, as sloppy hacks may be needed to debug speed or executable size issues.
<Tetralux>
Important question: In what way is var instead of const sloppy?
<Tetralux>
Also, I just updated my paste.
<_Vi>
Tetralux, Reader of the code spends time to see where is it modified and not finding any place.
<Tetralux>
If you're interested what might be a slight perf decrease with const vs var. :)
<Tetralux>
I'm open to the idea that I'm doing something wrong, but :)
<_Vi>
Is there a proper Zig online playground? (not just godbolt)
<fgenesis>
since when is godbolt not a proper playground
<_Vi>
fgenesis, Does it run the code or tests and show stdout/stderr?
<fgenesis>
optionally, yes
<Tetralux>
fgenisis: How?
<Tetralux>
fgenesis*
<Tetralux>
I've never seen that option.
<fgenesis>
i've seen the option i think but never used it; it's faily new iirc
<_Vi>
fgenesis, If yes and it is supposed use case of godbolt, then specialized godbolt-backed UI may be provided to act as a Zig playground. But I usually assume godbolt is when you need to insect asm / llvm ir.
<_Vi>
*inspect
<_Vi>
Using it for generic Zig noob playground may be misuse of godbolt's resources.
<Tetralux>
I ask because I have the opposite logic; if it's const, I just go "Oh - they don't modify this", and if it's non-const, I just assume that it can be modified -- not that it _is_ modified.
kristoff_it has quit [Ping timeout: 240 seconds]
<_Vi>
Tetralux, Rust, for example, has `unused_mut` warning. When you declare variable as mutable, but use this mutability.
<Tetralux>
But as I said, I use mutable vars everywhere - just because it strains my fingers to actually type const vs var, _and_, the real reason, I don't want to discover I need it to be mutable and have to break my flow and change it.
<_Vi>
Tetralux, Obviously, such warning is ignorable both at large scope and for individual var level.
<Tetralux>
Indeed, I've come across that warning myself.
<_Vi>
Tetralux, "var" may be OK for things that _may_ become mutable facing further code changes.
<_Vi>
Tetralux, If a thing is by principle immutable then better to use `const` even if `var` is accepted.
<Tetralux>
I've never come across a bug because something is mutable and wasn't, that I can recall.
<Tetralux>
and should not have been*
<Tetralux>
So far as I know, using const over var has never solved any of the problems I have encountered.
<_Vi>
Tetralux, This is not question of bug vs correct code. It is question about what unfamiliar reader of the code would feel.
<Tetralux>
I do not read code by whether things are immutable or not.
<Tetralux>
Using const would obviously mean that I knew you didn't change it.
<_Vi>
The fact that `var` is shorter than `const` can act against Zig goals of readable code.
<_Vi>
If it were `variable`, nobody would use it instead of `const` just to save typing, I suppose.
<_Vi>
Such thing is called "Syntactic salt" in Rust discussions.
<Tetralux>
If I had to type const or variable, I'd not use Zig xD
<_Vi>
Just shorten `const` to `co`. It would look weird although...
<fgenesis>
DECLARE VARIABLES a,b,c; ADD a TO b GIVING c
<fgenesis>
_Vi: first thing co triggers in my head is something to do with coroutines. plz no
<Tetralux>
I hate to say it, but Jai doesn't have this problem.
<Tetralux>
x := 0; // mutable.
<Tetralux>
x :: 0; const.
<_Vi>
Good middle ground may be: 1. Use `var` for things that are mutated at least once (or 0 or more times if sloppy mode); 2. Use `const` for things that are mutated 0 times; 3. Use `@allowConst var` for things that can be mutated 0 and more times, even in non-sloppy mode.
<fgenesis>
wat
<Tetralux>
I don't know who you're saying wat to fgenesis xD
<_Vi>
fgenesis, Shall I explain whats and whys?
<fgenesis>
wat = i just read 4 lines of irc about const and my brain derped
<_Vi>
The goals are: 1. To use familiar words like `var` and `const`; 2. To suppress usage of `var` where `const` suffices; 3. To allow temporary opt out of "2."; 4. To allow "escape hatch" if one really needs var that may be not mutated.
<fgenesis>
yes but it's already way too complicated for what it is
<fgenesis>
pile rules upon rules like this and eventually you end up with c++
<_Vi>
fgenesis, Which part is complicated?
<fgenesis>
yes
<fengb>
What's wrong with what we have right now?
<_Vi>
fengb, Looming doom of #224 ( add an error for using `var` when one could have used `const`)
<_Vi>
And the problem it is trying to solve (using `var` instead of `const`)
dimenus has quit [Read error: Connection reset by peer]
dimenus has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
fsateler has quit [Quit: ZNC 1.7.2+deb3 - https://znc.in]
fsateler has joined #zig
benaiah has quit [Remote host closed the connection]
benaiah has joined #zig
<vegai>
just remove vars altogether, they're the source of all bugs anyway :P
<vegai>
just bindings, bindings everywhere
<vegai>
I hope it's obvious I'm kidding
porky11 has joined #zig
<fengb>
Let's remove mutation altogether
<Tetralux>
fengb: Do so at your peril >)
<scientes>
_Vi he leffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffft?
<scientes>
I wouldn't worry about their resources as long as you aren't using it from a script, and godbolt is open source and you can run it locally if you want
Ichorio has joined #zig
<Tetralux>
andrewrk: #3037 updated and passing.
<andrewrk>
wow, I did not realize testing foreign architectures with qemu was this easy
<andrewrk>
it's literally just `qemu-riscv64 ./the_program`
<andrewrk>
it works with gdb too: `qemu-riscv64 -g 9000 ./the_program` (another terminal) `gdb ./the_program -ex 'target remote localhost:9000' -ex 'continue'
<andrewrk>
this is a total game changer, I'm going to add -Denable-qemu to zig build
<scientes>
andrewrk, you don't even have to do that if you set up binfmt_misc
<scientes>
oh, but didn't know you could use gdb with qemu-user-static like that, that is awesome
porky11 has quit [Ping timeout: 250 seconds]
<andrewrk>
ok I have a plan for how to get a lot more test coverage of other architectures now
<scientes>
cause ptrace doesn't work for obvious reasons
<Tetralux>
andrewrk: That...... sounds awesome.
kristoff_it has joined #zig
<Tetralux>
I find it interesting that doing `-target riscv64-windows` gives you `lld: error: .\test.obj: unknown file type`
<Tetralux>
Which makes no sense??
<Tetralux>
Turns out, `riscv64-linux` works fine though /shrug
<Tetralux>
Seems like a bad error to me.
kristoff_it has quit [Remote host closed the connection]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 240 seconds]
wilsonk has joined #zig
<wilsonk>
asdf
<wilsonk>
woops :)
<mq32>
password is safe
<andrewrk>
I would never guess that password, I use dvorak
<companion_cube>
is that why you type so fast?
Hirezias has quit [Quit: WeeChat 2.4]
<mq32>
i think it's more than andrewrk is either using Cherry MX Blue or a buckling spring keyboard
<mq32>
at least it sounded like he does in the streams
<scientes>
I actually didn't like dvorak much
<scientes>
didn't find it any better
<scientes>
12345, thats the type of password someone uses on their luggage
<companion_cube>
you mean 54321?
<companion_cube>
(unlike 12345, it's totally impossible to guess)
<scientes>
companion_cube, its a spaceballs reference
<scientes>
Linux has a few of those
<scientes>
in the source code
<companion_cube>
😅
tdc_ has joined #zig
tdc has quit [Ping timeout: 240 seconds]
tdc_ has quit [Quit: Leaving]
<stratact>
Wait, why am I getting this build error?
<stratact>
CMake Error at cmake/Findllvm.cmake:19 (message):
<stratact>
unable to find llvm-config
<andrewrk>
if you're working on master branch of zig you'll need to update your LLVM/clang libraries
<andrewrk>
llvm 9 released yesterday
<stratact>
Oh f*** I hope FreeBSD 12-STABLE gets the llvm 9 upgrade soon
<scientes>
stratact, considering that FreeBSD is build with llvm 9 some version of FreeBSD will
<stratact>
I'm going to do a system upgrade to see
<stratact>
Well at least I have ways to do it locally but I'm still going to an OS upgrade if I can get the latest llvm globally.
<andrewrk>
the release was yesterday, there's a 0% chance that it's in pkg already
<mikdusan>
also i have a freebsd script that builds from llvm-project mono-git-repository if you want it
<stratact>
andrewrk: llvm is in the freebsd source, I'm rebuilding the whole OS again from the latest svn revision :)
<andrewrk>
interesting
<mikdusan>
ports head for freebsd has: llvm90-9.0.0.r4_1 which is (9.0.0 rc4)
<stratact>
interesting, so I can have 2 versions installed?
<mikdusan>
i suspect you can have 3 versions. one that is the system default. and two more that are suffixed like "/usr/local/llvm80" and "/usr/local/llvm90"
<stratact>
mikdusan: I got a question, from doing the STABLE svn branch upgrade, I noticed this compiler output, "c++ -target x86_64-unknown-freebsd12.1" ... assuming I'm getting 12.1 early, would I still be able to run Zig?
<mikdusan>
when building zig, use the same compiler that built LLVM,
<mikdusan>
freebsd ports LLVM is using the default system compiler (I presume)
<mikdusan>
and when building Zig without any options or env vars overring things, it will use "c++" as well
<mikdusan>
and calling std.special.panic without 2nd arg?
<mikdusan>
just a hail-mary from me because i don't really understand it: "LLVM will now remove stores to constant memory (since this is a contradiction) under the assumption the code in question must be dead."
<stratact>
brb
stratact has quit [Quit: Konversation terminated!]