Auto-cast

Auto-cast

Jonathan Blow

10 лет назад

8,125 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@MenkoDany
@MenkoDany - 24.04.2015 22:47

I like acast better than special chars, it's unlikely to show up as part of var name or something of that ilk. Maybe if you misspell spellcast.

Ответить
@schm·amie
@schm·amie - 24.04.2015 23:15

I thought maybe renaming cast to forge, and call autocast cast. Renaming cast seems silly, but forge seems like a stronger concept than casting so that was my logic

Ответить
@dietermuller4345
@dietermuller4345 - 24.04.2015 23:43

Which theme are you using,i mean this c++ theme, pls tell me

Ответить
@GaMatecal
@GaMatecal - 24.04.2015 23:54

First time commenting, been religiously watching your videos, and is very enjoyable :D

I have a question though.  Why use 'xx' as the autocast?  All of the other syntax makes sense, and very easy to understand.  xx means nothing to me, even if I knew it was autocast.  I prefer acast in my opinion.

Here is food for thought.  'cast(type) value' is obvious, and I know what it means.  Just like 'acast value'.  But now it's some two letters... maybe its 'ac value'?  Nope... Maybe it was 'aa value'?  Nope...  Maybe I was wrong, lets check docs. (1minute later)  Damnit Jonathan >:|

If you really want it small like that.  Instead of 'xx', use 'ac' for autocast maybe?

Ответить
@LukeDrumm
@LukeDrumm - 25.04.2015 00:20

Random thought: The thing that has always bugged me about pointer math in C++ is that it's very easy to forget / misread the code as dec/incrementing by single bytes instead of entire bytes / words / struct sizes. How about making this explicit by introducing a symbol to denote that it's not incrementing by single bytes? e.g. newAddress += 2 * that (where "that" is a symbolic representation of the size of increment).

Ответить
@ashlynartificia
@ashlynartificia - 25.04.2015 03:34

i really like the "as" from C#

Ответить
@i.donthaveanameanymore
@i.donthaveanameanymore - 25.04.2015 05:34

,, is really nice in my opinion

Ответить
@theb1rd
@theb1rd - 25.04.2015 13:45

Maybe "coerce"

Ответить
@helmutb.7075
@helmutb.7075 - 25.04.2015 16:19

I think the postfix notation wouldn't be so bad. This:
x = y cast(Type);
would naturally be pronounced as "x gets the value of y casted to Type". If you put the cast on the left side you couldn't pronounce it in the same order.
Also all definitions have the name on the left side and the type on the right. It would only be natural for casts to have the type on the right side as well.
Last argument: If I write a statement, I usually write the statement first and insert the necessary casts last. So I usually have to go back to the middle of the statement and insert the cast. With the cast on the right side this process would be much easier.

Ответить
@Dengakuman22
@Dengakuman22 - 26.04.2015 00:35

I think something like acast is already quick enough to type. Anyone needing any more speed than that to type a cast is either casting to much or needs to improve his typing speed.

Also, I just realised by changing the cast syntax to prefix operator you made it regular, so it's really an improvement. Specially if searching and replacing for casts / auto casts ends up being an important thing in the language.

Ответить
@GingerGames
@GingerGames - 26.04.2015 01:10

I'm still not sure why cast(var, type) isn't a good option?

What if you did something like C++ cast<type>(var) or cast(type)varOr how about: var as type

Ответить
@Fangornmmc
@Fangornmmc - 26.04.2015 02:41

Jonathan Blow cast(type) val or cast(val) both seem fine to me. XX seems quite meaningless though... suggestions:

return ?? result;
return var result;

Trouble with ?? is that it could be in comments, so that could be a minor irritation when you're trying to find-and-replace casts.

As for bitwise operators, while I understand you consider those to be high-value, I am not sure if it's something that you should change. In other words, until there's an actual use-case where you might want to use & | etc, I would just leave them untouched. Just my opinion, but those operators are so consistent over a whole range of programming languages that it seems odd to go against the norm.

Ответить
@error17_
@error17_ - 26.04.2015 04:22

If it were me I would like casting like
<u32>result
and auto
<> result or <?> result

Ответить
@aameen951
@aameen951 - 26.04.2015 10:07

how does the byte code work ?
Is he generating assembly?
or Is he using some library?

Ответить
@MSheepdog
@MSheepdog - 27.04.2015 06:33

FYI:
Moving breakpoints in later VS can still be achieved by right clicking on the breakpoint (either in the source or breakpoint windows), going to 'localtion', and changing the line number.
It's not as nice and dragging it around, but at least it saves you from retyping the conditions.

Ответить
@SpelMalmer
@SpelMalmer - 28.04.2015 20:59

In my opinion "acast" is easily the clearest in intent while also fast to type.

Ответить
@0xPulcra
@0xPulcra - 30.04.2015 10:49

I personally would have gone with @ ... it's like an 'a' and a 'c' all rolled in to one, conveniently a shorthand for the initials of autocast.

Ответить
@ragharu
@ragharu - 05.05.2015 16:44

I would consider replacing "cast" with "as" - it is easier to type (a and s lies next to each other). Then auto inferred cast would be something like "as?" where question mark would highlight that type is "guessed".

Ответить
@0xCAFEF00D
@0xCAFEF00D - 02.08.2015 21:30

I really like the double underscore. Double comma would clash with the way I write stuff when using functions. I usually put the commas and step between them inserting whatever I wanted to pass. If I missed two arguments that'd be a cast into an overloaded function.

But I acknowledge that what I do is weird and stupid.

Ответить
@aavamaki
@aavamaki - 18.09.2015 14:47

Most likely

return acast result; <- most unequivocal
return as result; <- most C#
return ?! result; <- most hilarious

(I actually kinda like "?!"; ? implies inferred or queried, ! implies cast or decree. Not great for comment search-replace, I'll admit.)

Ответить
@ihrbekommtmeinenrichtigennamen
@ihrbekommtmeinenrichtigennamen - 21.10.2015 00:05

I'm figuratively screaming at my screen here :P
It's an auto-cast. Call it "autocast".

Ответить
@localatticus4483
@localatticus4483 - 24.03.2016 19:22

I personally would've (and am currently planning to) use `auto` as my autocast keyword. I could also use `cast` since my casting is done as `expr as type`.

Ответить
@Kavukamari
@Kavukamari - 02.08.2017 01:36

this comment is outdated by now, but I enjoy acast for explicitness

void cast like "cast()" appeals to me too cause it's still explicit and searchable

xx ,, __ >< doesn't strike me as explicitly a "casting" thing, but i guess that's because they don't exist yet

I like the "cast" "forge" semantics suggested by other comments

Ответить
@dimarichmain
@dimarichmain - 01.08.2021 20:24

What is "poison" in types list? Some kind of debugging thing?

Ответить