V: Questions regarding this language?

Created on 3 Aug 2020  Â·  23Comments  Â·  Source: vlang/v

Hi, this programming language looks very interesting but I have a few questions regarding this project:

  1. Is this a compiled language?
  2. Is this language as low level as Rust and C?
  3. What are the upsides and downsides of using this language in comparison to Rust?
  4. Does this language have a borrow checker like Rust does?
  5. Is this language a statically typed language, for example during compile time the compiler has to know the variable's data type?
  6. Is this in its stable form this language?
  7. I heard that you can translate C code into V code and with C++ it is experiental. Does it also support translating Arduino C++ code into V code?
  8. When did the development of this language initially start?
  9. When using for loops am I able to use C-style for loops, for example:
for (i int = 0; i < 10; i++)
{
// Does something
}
Question

Most helpful comment

Already part of the server now :)

On Wed, Aug 5, 2020 at 12:40 AM JalonSolov notifications@github.com wrote:

There's an icon on the home page to send you to discord, as well. :-)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/vlang/v/issues/6044#issuecomment-668636741, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AIKO7IMC2CYCY72ABK7TUELR7AMVLANCNFSM4PS5GGBQ
.

All 23 comments

@Joe23232 Can't speak in behalf of the team, but I'll try to answer all of your questions:

  1. Is this a compiled language? Yes.
  2. Is this language as low level as Rust and C? Its within the same level as c since its generating code C as IR code.
  3. What are the upsides and downsides of using this language in comparison to Rust?
    I can't tell about that since I haven't tried Rust yet. @medvednikov and @spytheman might answer it?
  4. Does this language have a borrow checker like Rust does? Nope.
  5. Is this language a statically typed language, for example during compile time the compiler has to know the variable's data type?
    It's a statically typed language.
  6. Is this in its stable form this language? Not yet but we're close to stabilizing the features, the syntax and the modules.
  7. I heard that you can translate C code into V code and with C++ it is experiental. Does it also support translating Arduino C++ code into V code? The translator C2V is yet to be worked on the 0.3 version which in a distant future.
  8. When did the development of this language initially start? Not sure when but afaik the first public development started on May/June of last year.

@Joe23232 For your recent question, yes you can.

for i := 0; i < 10; i++ {
  // do something
}

Docs: https://github.com/vlang/v/blob/master/doc/docs.md#for-loop

Can't speak in behalf of the team, but I'll try to answer all of your questions:

Thank you mate :)

Its within the same level as c since its generating code C as IR code.

Sorry what does IR stand for?

Not yet but we're close to stabilizing the features, the syntax and the modules.

That is great :)

Does this language have a borrow checker like Rust does? Nope.

Doesn't that make it more dangerous to not have a borrow checker, unless if it has a garbage collector?

The translator C2V is yet to be worked on the 0.3 version which in a distant future.

Ah I see hope to see it soon. Does it support Arduino if I directly write it as V code?

Not sure when but afaik the first public development started on May/June of last year.

Oh wow, it seems pretty amazing this language.

For your recent question, yes you can.

Oh that is nice, I kinda missed this C-like for loop style as Rust does not have that.


Just curious why are variables assigned a value in this fashion i := 0 rather than the typical way of doing i = 0?

Sorry what does IR stand for?

IR means Intermediate Representation. It is used for post-processing the code like putting optimizations and etc before translated into target instruction set. Rust uses LLVM for that.

Doesn't that make it more dangerous to not have a borrow checker, unless if it has a garbage collector?

V does not use GC and has its own memory management (https://aardappel.github.io/lobster/memory_management.html) I can't go into that since I'm not an expert at it. :smiley:

Ah I see hope to see it soon. Does it support Arduino if I directly write it as V code?

It's a feature request as of now (See #4115). But we'll get there soon

Just curious why are variables assigned a value in this fashion i := 0 rather than the typical way of doing i = 0?

Just to quote on this one:

Variables are declared and initialized with :=. This is the only way to declare variables in V. This means that variables always have an initial value.

Source: https://github.com/vlang/v/blob/master/doc/docs.md#variables

IR means Intermediate Representation. It is used for post-processing the code like putting optimizations and etc before translated into target instruction set. Rust uses LLVM for that.

Ah I see.

V does not use GC and has its own memory management (https://aardappel.github.io/lobster/memory_management.html) I can't go into that since I'm not an expert at it. smiley

Oh thanks for the link :)

It's a feature request as of now (See #4115). But we'll get there soon

Oh nice, hopefully to see it soon.

Source: https://github.com/vlang/v/blob/master/doc/docs.md#variables

I understand now.

@Joe23232 about your question :

  1. What are the upsides and downsides of using this language in comparison to Rust

Rust positives: It is an older language, so probably much more stable and proven (there are even entire kernels written in Rust). It has a borrow checker, that guarantees at compile time, that some classes of bugs will not be possible at runtime. Its memory management story and concurrency support, are more or less complete, while in V, they are still WIP. Its documentation is more complete. It has more tooling (their cargo tool is awesome). It is backed by megacorporations. It has much larger community (for now ;-) ), so may be it may be easier to find help from independent vendors (aka other people on the Internet :-) ).

Rust negatives: The compiler is more complex, and thus harder to understand/modify for your needs. The generated binaries are much larger by default. The compilation speed for larger projects may become a problem. The syntax is uglier than V's (that is just my personal opinion). Not only is the language syntax more complex, but there are much more concepts, that you need to understand in Rust, before you can use the language effectively, while you can learn the basics of V, and be productive in it, in just a couple of hours.

In general, Rust tries to give you much more freedom, on what you can do with the language (it even has a macro system, so you can extend the syntax of the language), and with its tooling. If you need that expressive freedom, I would say that V may not be for you - V strives to be not a stripped down ML/Lisp, but an enhanced C/Go - Simple, fast, safe, compiled. For developing maintainable software. V usually has just one way for most things - you may not like its one way, but it is simpler than supporting everything possible, and it is usually enforced by V's tooling => projects written in V, would tend to look more or less the same, while ones written in Rust, will have much greater variance.

A good example for that in action is https://github.com/rust-lang/rustfmt - the official code formatting tool for Rust explicitly says: "Rustfmt is designed to be very configurable." . In contrast, V's equivalent is part of the main V repository (see https://github.com/vlang/v/blob/master/cmd/tools/vfmt.v and https://github.com/vlang/v/blob/master/vlib/v/fmt/fmt.v ) and is deliberately NOT configurable (its options control its behavior, not the style of formatted code that it produces).

Rust positives: It is an older language, so probably much more stable and proven (there are even entire kernels written in Rust). It has a borrow checker, that guarantees that some classes of bugs are not possible at runtime.

I thought V had something similar according to @nedpals link: https://aardappel.github.io/lobster/memory_management.html (sorry I am not a developer I have no idea how this stuff works I still very beginner.)

The syntax is uglier than V's (that is just my personal opinion). Not only is the language syntax more complex, but there are much more concepts, that you need to understand in Rust, before you can use the language effectively,

I couldn't agree with you more. Its too difficult to learn to the point where it makes the stuff that I was originally working on too tedious while not even understanding some stuff. When I write code I want to be able to understand what is actually going on.

while you can learn the basics of V, and be productive in it, in just a couple of hours.

That is great to know :)

(it even has a macro system, so you can extend the syntax of the language)

Would V eventually implement this as this seems like a useful feature?

If you need that expressive freedom

When you state _expressive freedom_, are you just referring to its macro system?

V usually has just one way for most things - you may not like its one way, but it is simpler than supporting everything possible, and it is usually enforced by V's tooling

So that means I have less control over what my application does with V compared to Rust is that what you mean?

and it is usually enforced by V's tooling => projects written in V, would tend to look more or less the same,

Are you referring to its user interface when developing GUI applications?

@Joe23232 memory management is a Work In Progress right now in V.

About the macro system - as far as I know, there are no plans to implement one in V.

About your other questions - I am referring mostly to the look&feel of source code of all V programs, not to a specific UI library/framework.

memory management is a Work In Progress right now in V.

AH I see.

About the macro system - as far as I know, there are no plans to implement one in V.

Wouldn't it benefit V even further if the macros feature were to be implemented?

About your other questions - I am referring mostly to the look&feel of source code of all V programs, not to a specific UI library/framework.

Oh I see, my bad.

On macros... no, it is not a benefit. Just do a Google search for "why are macros bad", or even "why are macros bannable". Here's just one of many lists I found for why macros are bad:

  • The compiler has no way of checking that a macro is semantically closed, i.e. that it represents a “unit of meaning” like a function does. (Consider #define TWO 1+1 — what does TWO*TWO equal? In this case 3. (1 + 1 * 1 + 1... operator precedence does the multiplication first, so you have 1 + 1 + 1 which equals 3)

  • Macros are not typed like functions are. The compiler cannot check that the parameters and return type make sense. It can only check the expanded expression that uses the macro.

  • If the code doesn’t compile, the compiler has no way of knowing whether the error is in the macro itself or the place where the macro is used. The compiler will either report the wrong place half of the time, or it has to report both even though one of them is probably fine. (Consider #define min(x,y) (((x)<(y))?(x):(y)): What should the compiler do if the types of x and y don’t match or don’t implement operator

  • Automated tools cannot work with them in semantically useful ways. In particular, you can’t have things like IntelliSense for macros that work like functions but expand to an expression. (Again, the min example.)

  • The side-effects of a macro are not as explicit as they are with functions, causing potential confusion for the programmer. (Consider again the min example: in a function call, you know that the expression for x is evaluated only once, but here you can’t know without looking at the macro.)

Oh wow, if Rust cares about safety more than convenience, why even implement macros in the first place?

I have no idea why Rust does anything... or why it even exists. :-) I took one look at the complexity of the syntax and decided it was not for me.

or why it even exists. :-)

From what I understand they wanted to address all the memory related issues, data races etc, something that C and C++ fails to do. I feel like V implemented some of Rust's philosophy, for example, no global variable declaration, immutability by default. I think Rust really was trying to make a safe language, but they kinda made it overly complicated with their language.

I took one look at the complexity of the syntax and decided it was not for me.

Yes its very confusing. I have no idea what is anything going on :( Also I have no idea why they changed their for loops. They really made it inconvenient to use. At least V has the same C-style for loop.

Even with C I feel like I can learn a little more compared to Rust. On top of that I was trying to make some basic application that goes with lemonbar (it takes stdin and outputs information into the bar) but I found it too difficult in Rust. I hope V can be much easier to implement.

I am going to try and use shell commands within V (I was trying to do this in Rust for the lemonbar project), and hopefully it is much easier to implement. With shell commands within V, it will run as a compiled language, not as a scripting language, am I correct?

You can run V whichever way you prefer. You can run it as a scripting language with .vsh files, or you can compile it to a native executable. Your choice.

I recommend reading the documentation first (it's not terribly long... 1/2 to a couple of hours, depending on your reading speed.

You can find links to the documentation, the "wasm playground" (it actually runs V which has been compiled to a WASM module for your browser, IN your browser), etc. on the home page, https://vlang.io/

You can run V whichever way you prefer. You can run it as a scripting language with .vsh files, or you can compile it to a native executable. Your choice.

Will it run faster if it is compiled to native executable compared to scripting language?

I recommend reading the documentation first (it's not terribly long... 1/2 to a couple of hours, depending on your reading speed.

Much better than the Rust's long book.

You can find links to the documentation, the "wasm playground" (it actually runs V which has been compiled to a WASM module for your browser, IN your browser), etc. on the home page, https://vlang.io/

Oh that is pretty neat you guys have that :)


By the way how does V compile code at a very fast speed compared to any other languages out there, that is pretty amazing.

One of the selling points of V is that there is "one way" to do pretty much anything, and that equates to a well-defined syntax that is very fast to parse and generate code from. It outputs a single C file in the default backend, with no #includes or any of the rest of that stuff that can slow down the C compiler, so the C compiler runs fast as well.

If you use the -prod switch, it is a different story, as V then tells the C compiler to do optimizations, which slows the compile down... sometimes by a quite noticeable amount. Most of the time, you don't need to do this, but if you have something that takes a long time to run after it is compiled, compiling it with -prod could speed the executable up at the cost of a longer compile time.

One of the selling points of V is that there is "one way" to do pretty much anything, and that equates to a well-defined syntax that is very fast to parse and generate code from. It outputs a single C file in the default backend, with no #includes or any of the rest of that stuff that can slow down the C compiler, so the C compiler runs fast as well.

Ah I see.

If you use the -prod switch, it is a different story, as V then tells the C compiler to do optimizations, which slows the compile down... sometimes by a quite noticeable amount. Most of the time, you don't need to do this, but if you have something that takes a long time to run after it is compiled, compiling it with -prod could speed the executable up at the cost of a longer compile time.

I guess the best thing is that once when the program has been finalised then use the optimised flags. When testing out the code best to avoid these flags.

Additionally am I able to use other flags like -O3 and -Ofast?

Use -cflags '-Ofast' @Joe23232 . Also in general, asking questions in issues is fine, but reading the fine https://github.com/vlang/v/blob/master/doc/docs.md is much superior, for saving everyone's time.

If you want to chat about V, and get answers and help for problems encountered while using/learning it - https://discord.gg/vlang

Ok thanks, didn't realise there was a discord server.

On Tue, Aug 4, 2020 at 11:50 PM Delyan Angelov notifications@github.com
wrote:

If you want to chat about V, and get answers and help for problems
encountered while using/learning it - https://discord.gg/vlang

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/vlang/v/issues/6044#issuecomment-668608107, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AIKO7IPI6HAZUMSFBG3EC53R7AG3HANCNFSM4PS5GGBQ
.

There's an icon on the home page to send you to discord, as well. :-)

Already part of the server now :)

On Wed, Aug 5, 2020 at 12:40 AM JalonSolov notifications@github.com wrote:

There's an icon on the home page to send you to discord, as well. :-)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/vlang/v/issues/6044#issuecomment-668636741, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AIKO7IMC2CYCY72ABK7TUELR7AMVLANCNFSM4PS5GGBQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taojy123 picture taojy123  Â·  3Comments

ArcDrake picture ArcDrake  Â·  3Comments

lobotony picture lobotony  Â·  3Comments

PavelVozenilek picture PavelVozenilek  Â·  3Comments

markgraydev picture markgraydev  Â·  3Comments