Thread overview | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 13, 2016 Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
So I fly to Cologne tomorrow morning, and will be presenting on Tuesday. Got my talk written, gave it a dry run at the office and got feedback on it. Seems to be in a good spot. But before I go up and feature compare to other languages, it'll be a good idea to get my facts right. There's three spots in my talk where I go through some D code, and then show a table indicating whether the features I used in those examples are available in other, trendier languages. In some cases, the features become available with after-market add ons. But I'm focusing exclusively on stuff you can get out of the box, ie write some code and compile it with a stock DMD/LDC/GDC/SDC install and it'll Just Work(TM). So here's a dodgy table indicating the features I'm showing on the slides, and the languages that are most relevant to game developers - C# and Swift - with Rust thrown in since that's the new language everyone knows about. If I've got something wrong with the out-of-the-box solution, please let me know. If there is something you can do with an add-on, also let me know since it will allow me to prepare for the inevitable audience questions saying "but you can do this with this etc etc" | Rust | Swift | C# | -----------------------------|---------+---------+---------| Template Constraints | Y | Y | where | [1] -----------------------------|---------+---------+---------| Template "if" Constraints | where | where | where | -----------------------------|---------+---------+---------| static if | N | N | N | -----------------------------|---------+---------+---------| Eponymous templates | N | N | N | -----------------------------|---------+---------+---------| Compile time reflection | N | N | N | -----------------------------|---------+---------+---------| CTFE | N | N | N | -----------------------------|---------+---------+---------| User defined attributes | Crates | Runtime | Y | -----------------------------|---------+---------+---------| Deep function inspection | N | N | N | -----------------------------|---------+---------+---------| Mixins | N | N | N* | [2] -----------------------------|---------+---------+---------| [1] Limited comparisons can be made with template where constraints [2] Mixins in swift are essentially traits and protocol extentions, not like D mixins at all |
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ethan Watson | On 08/13/2016 02:47 PM, Ethan Watson wrote:
> | Rust | Swift | C# |
> -----------------------------|---------+---------+---------|
> Template Constraints | Y | Y | where | [1]
> -----------------------------|---------+---------+---------|
> Template "if" Constraints | where | where | where |
What's a 'template "if" constraint'? Template constraints already use the `if` keyword. This is a template constraint:
template Foo(T) if (is(T : int)) {/* ... */}
Other than those, there are template specializations. Example:
template Foo(T : int) {/* ... */}
|
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ethan Watson | On Saturday, 13 August 2016 at 12:47:40 UTC, Ethan Watson wrote: > > | Rust | Swift | C# | > -----------------------------|---------+---------+---------| > Template Constraints | Y | Y | where | [1] > -----------------------------|---------+---------+---------| > Template "if" Constraints | where | where | where | > -----------------------------|---------+---------+---------| > static if | N | N | N | > -----------------------------|---------+---------+---------| It might be something to note that C# doesn't have templates. Generics can only have type parameters (i.e. `int` or `string` not `5` or `Hello World`), and the `where` constraint is pretty restricted in what it can do: o Is T or is subclass of T/implements interface (class C<T> where T : U) o Default/parameterless constructor (class C<T> where T : new()) o Reference/value type checking (class C<T> where T : class/where T : struct) For "static if," C# also has a very limited conditional compilation system that is barely comparable. Symbols can be defined at compile time, but they can't have values and they can only be used with specific directives: --- #define X #if X doA(); #else doB(); #endif --- |
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On Saturday, 13 August 2016 at 12:58:36 UTC, ag0aep6g wrote:
> What's a 'template "if" constraint'? Template constraints already use the `if` keyword. This is a template constraint:
>
> template Foo(T) if (is(T : int)) {/* ... */}
>
> Other than those, there are template specializations. Example:
>
> template Foo(T : int) {/* ... */}
Bad naming on my part. I'll rename it. Although considering type deduction/parameter matching/specialisation is syntactically related, I'll find a better umbrella name for that.
|
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Liam McSherry | On Saturday, 13 August 2016 at 13:02:09 UTC, Liam McSherry wrote:
> For "static if," C# also has a very limited conditional compilation system that is barely comparable.
This is covered in more detail in the talk itself when I compare static if to C style preprocessors. I would hope everyone in the room knows the C# preprocessor is limited compared to a C/C++ preprocessor. And if not, someone will either ask or Google it themselves after the event.
|
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ethan Watson | On 13/08/16 14:47, Ethan Watson wrote: > So I fly to Cologne tomorrow morning, and will be presenting on Tuesday. > Got my talk written, gave it a dry run at the office and got feedback on > it. Seems to be in a good spot. > > But before I go up and feature compare to other languages, it'll be a > good idea to get my facts right. > > -----------------------------|---------+---------+---------| > Compile time reflection | N | N | N | > -----------------------------|---------+---------+---------| > CTFE | N | N | N | > -----------------------------|---------+---------+---------| It would be interesting to here what's the view of macros in Rust when it comes to CTFE and compile time reflection. Macros evaluate at compile time and to be usable they need to support compile time reflection. Or are macros consider something different? > -----------------------------|---------+---------+---------| > Deep function inspection | N | N | N | > -----------------------------|---------+---------+---------| What is "Deep function inspection"? -- /Jacob Carlborg |
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Saturday, 13 August 2016 at 15:51:18 UTC, Jacob Carlborg wrote:
> What is "Deep function inspection"?
In the context of my talk, a collection of methods to inspect all function traits including parameter types and defaults etc. C++ can do type inspection. I believe Swift has something like Objective C does but I did not find concrete info on it. No idea about Rust.
|
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Liam McSherry | On Saturday, 13 August 2016 at 13:02:09 UTC, Liam McSherry wrote:
> On Saturday, 13 August 2016 at 12:47:40 UTC, Ethan Watson wrote:
>>
>> | Rust | Swift | C# |
>> -----------------------------|---------+---------+---------|
>> Template Constraints | Y | Y | where | [1]
>> -----------------------------|---------+---------+---------|
>> Template "if" Constraints | where | where | where |
>> -----------------------------|---------+---------+---------|
>> static if | N | N | N |
>> -----------------------------|---------+---------+---------|
>
> It might be something to note that C# doesn't have templates.
Not true. C# use generic (aka type erasure) for objects, but use template for value types. C# doesn't make the difference at the language level, but that is obvious from the fact that there is no way to do generic for value types.
C# even does virtual dispatch on them, by storing a hashmap in the vtable and looking up implementation from typeinfos.
|
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ethan Watson | On Sat, 13 Aug 2016 16:19:08 +0000, Ethan Watson wrote: > On Saturday, 13 August 2016 at 15:51:18 UTC, Jacob Carlborg wrote: >> What is "Deep function inspection"? > > In the context of my talk, a collection of methods to inspect all function traits including parameter types and defaults etc. C++ can do type inspection. I believe Swift has something like Objective C does but I did not find concrete info on it. No idea about Rust. C# can do this. Check System.Reflection.MethodInfo and System.Reflection.ParameterInfo. ParameterInfo has properties Attributes, CustomAttributes, ParameterType, and DefaultValue that you can inspect. (Attributes are for things like out and ref parameters; CustomAttributes are for [UserDefinedAttributes].) |
August 13, 2016 Re: Fact checking for my talk | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Wright | On Saturday, 13 August 2016 at 17:19:42 UTC, Chris Wright wrote:
> C# can do this. Check System.Reflection.MethodInfo and System.Reflection.ParameterInfo.
Runtime only? I'll make the distinction on my slides.
|
Copyright © 1999-2021 by the D Language Foundation