Author Topic: Keyword "func" - redundancy?  (Read 56 times)

acbaile

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Keyword "func" - redundancy?
« on: September 22, 2018, 02:05:30 AM »
Is keyword "func" necessary? It seems like redundancy. C does not have this keyword, and knows where function begins. What is reason of introducing this keyword?

I think, in early variants of C return type of function by default was void. So, when you omit return type of function in declaration - it's procedure:

procedure(){

}

When you specify return type - it's function:

uint64
function(){

}

I find this is beautiful and by spirit of C :) . My opinion. Maybe "func" is better.
« Last Edit: September 22, 2018, 02:07:16 AM by acbaile »

bas

  • Full Member
  • ***
  • Posts: 177
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #1 on: September 24, 2018, 12:19:34 PM »
If the func keyword was completely redundant it would have been removed indeed. The keyword does make it a lot
easier on the parser. For a human it probably looks redundant. I was initially thinking about 3 keywords for globals:
type, func and (var?). That way it's completely obvious. Many new languages use something like this because making
stuff utterly obvious is usually a good thing. I did not add the (var?) keyword, because I felt that all variables should then
use it; so also local variables. This make the function bodies less easy to read, so now types and functions have a
keyword and variables don't.

acbaile

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #2 on: September 25, 2018, 01:41:04 AM »
It's clear. Okay. "func" is good, "funny" word :) .

magnusi

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #3 on: November 09, 2018, 11:08:21 PM »
@acbaile If you used SML, it would be even funnier, because the keyword there is just fun  :)

I agree about the keywords. Another point is that even though they might seem redundant, they make it easier to read for humans as well. The moment you see the keyword, you immediately know what you are dealing with, as opposed to having to read the whole line (or more). The difference is tiny, but it is still there, I'd say.

On the topic of variable keyword, I'd say it depends on the language. In languages Rust, SML, OCaml and Reason, that have some form of type inference, the let or val keywords work pretty well. The line is shorter, clearer and tells us what we need, with optional explicit type specification being just : Type away.

However, so long as C2 doesn't have variable type inference (or any inference for that matter) I think that not having a var keyword is a much better idea. I remember from the days of yore, when I still used AS3, that declarations like this felt pretty cluttered (taken from graphicscorelib):

Code: [Select]
        internal var _spriteSheet : GPUSpriteSheet;
        internal var _vertexData : Vector.<Number>;
        internal var _indexData : Vector.<uint>;
        internal var _uvData : Vector.<Number>;
        protected var _context3D : Context3D;
        protected var _parent : GPUSpriteRenderStage;
        protected var _children : Vector.<GPUSprite>;
        protected var _indexBuffer : IndexBuffer3D;
        protected var _vertexBuffer : VertexBuffer3D;
        protected var _uvBuffer : VertexBuffer3D;
        protected var _shaderProgram : Program3D;
        protected var _updateVBOs : Boolean;

If we were able to see type earlier, I feel like it would have been cleaner.

lerno

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #4 on: November 10, 2018, 03:47:41 PM »
I've written about it before, but my opinion is that type inference of variables is mostly driven by generics.

If you have

Code: [Select]
std::vector<std::shared_ptr<Foo>> x = foo();
return x.size() > 0 ? x[0] : std::shared_ptr<Foo>();

Then obviously

Code: [Select]
auto x = foo();
return x.size() > 0 ? x[0] : std::shared_ptr<Foo>();

Is a great relief, but if the code was:

Code: [Select]
Foo *x[] = foo();
return x.size() > 0 ? x[0] : NULL;

Then type inference makes the code worse:

Code: [Select]
auto x = foo();
return x.size() > 0 ? x[0] : NULL;

acbaile

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #5 on: November 13, 2018, 05:25:47 PM »
@acbaile If you used SML, it would be even funnier, because the keyword there is just fun  :)

Bas, what do you think about "fun" instead of "func" ?

lerno

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #6 on: November 13, 2018, 08:43:33 PM »
It's used in a several languages. I think I prefer func.