Author Topic: deleted  (Read 10101 times)

acbaile

  • Newbie
  • *
  • Posts: 22
    • View Profile
deleted
« on: September 22, 2018, 02:05:30 AM »
deleted
« Last Edit: January 27, 2019, 09:12:38 PM by acbaile »

bas

  • Full Member
  • ***
  • Posts: 220
    • 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.

magnusi

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #2 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: 247
    • View Profile
Re: Keyword "func" - redundancy?
« Reply #3 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;

lerno

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