Getting errors from the compiler with vet while using the keyword "using" the way it is used in the docs

Hello everyone.

I started learning Odin from the examples given in the documentation at Overview | Odin Programming Language

From what i see in the online documentation, the keyword “using” is being used as as kind of “super-powered” pascal like “with” statement and for enabling runtime polymorphism in combination with structs.

But when i try to compile the following examples from the documentation i get the errors:

‘using’ as a statement is not allowed when ‘-vet’ or ‘-vet-using’ is applied

and

‘using’ is considered bad practice to use as a statement outside of immediate refactoring

The Odin example code from the documentation is the following:

Vector3 :: struct{x, y, z: f32}
Entity :: struct {
	position: Vector3,
	orientation: quaternion128,
}

foo1 :: proc(using entity: ^Entity) {
	fmt.println(position.x, position.y, position.z)
}


foo2 :: proc(entity: ^Entity) {
	using entity
	fmt.println(position.x, position.y, position.z)
}

foo3 :: proc(entity: ^Entity) {
	using entity.position
	fmt.println(x, y, z)
}

import "foo"

bar :: proc() {
	// imports all the exported entities from the `foo` package into this scope
	using foo
}


main :: proc() {

	Foo :: enum {A, B, C}
	using Foo
	a := A
...

Can anyone explain why i get these errors and what they mean?

Thank you very much in advance.

There is an interview with Ginger Bill on Youtube somewhere where he says that he kinda regrets even putting using into the language. He believes that it is useful for refactoring so he won’t remove it, but really does not want people to think that it’s idiomatic Odin.

Should be around minute 38 somewhere. https://www.youtube.com/watch?v=fYUruq352yE

I don’t “regret” it nor do I say that in any interview. I say it’s one of those features which is so easily abused. It’s something I only recommend for refactoring purposes, and nothing permanent.

You say you “actually regret adding this as a feature” at 38:27. Maybe you were talking about some specific use case of using which is not allowed anymore. Well, the point is the same in any case :person_shrugging:

So in that video, I regret it in the sense that it should have been something like Pascal’s with which is scoped, rather than the current inline behaviour.

However, using is still useful. It’s one of those features which is annoying but cannot be removed.

1 Like

Thank you very much for the answer and the link to the video GigaCrunch. I watched the corresponding part of the video for clarification.

But if that is still the current state then i think the examples for “using” should be removed from the documentation. It’s confusing. On the one hand the examples tell you that this is the proper usage for using “using” and when you try to compile code like in the examples you get an error message which tell you exactly the opposite.

This is at least inconsistent

Then why not change it and make it consistent while Odin is still in its infancy?

I don’t think that at the moment it would break a lot of code. The compiler and ols already give errors by default when using it this way.

Or come up with different solutions for refactoring and polymorphism than using “using” before Odin becomes more widespread.

Odin is not “still in its infancy”. Do you know how many multi million lines of code that people depend on now? We have nearly a million at our company alone. So even adding a new keyword, let alone change the semantics is a risky thing.

You thinking it won’t break a lot of code is honestly wrong.

Sorry gingerBill if my post might came across the wrong way. It clearly was not meant to offend and i feel sorry that you see it this way.

And thank you very muching for sharing your point of view.

With “in its infancy” i meant compared with programming language “dinosaurs” like C / C++ (from the 1970s or 1980’s). In comparison with these languages Odin is obviously still relatively young.

So i thought, that if you, as the language designer and BDFL of Odin, state in an interview, that a language design decision you did at a very early stage of language design, where the future implications where not foreseeable, is something that you would now rather change, then it might still be early enough to do so, before even more million lines of code will be written by your company and many more people in the industry.

And thanks for sharing the success story of Odin at JangaFX. It is good to hear for the community of Odin developers that their trust in Odin is more than justified.

I believe that at your company JangaFX which offers such an outstanding and sophisticated product there are many very talented developers which together with your support, the Odin language designer himself, could cope with such a breaking enhancement.

But as you have written, if such a large amount of code will be effected, it might be better not to fix it.

Thanks again for the clarification, your answers, and of course for the great Odin programming language.