Fixing C's Biggest Mistake

H. S. Teoh hsteoh at qfbox.info
Thu Jan 5 21:24:33 UTC 2023


On Thu, Jan 05, 2023 at 08:58:52PM +0000, areYouSureAboutThat via Digitalmars-d wrote:
[...]
> But in that case, what are people fussing about. Just use that.
> 
> Why introduce nonsense such as this: [$] [..]  ???

As you said yourself later, syntax. ;-)


> Mmm .. maybe [?]   ??

`?` is the ternary operator, it's weird to use it in this context with a
totally unrelated meaning.


> btw. I don't consider syntax as bikeshedding. As a programmer, nothing
> is more important to me than sensible (and predictable) syntax.

Syntax certainly has its place (I wouldn't ever want to use C++ template
syntax again unless I'm forced to, for example), but semantics is far
more important in a programming language than syntax.  The prettiest
syntax in the world is worthless if it cannot express what I want to
express in my code, or if it has weird semantics with strange corner
cases that make my code hard to understand.


> However, instead of having to do this:
> 
> auto myArray = [0, 1].staticArray;
> 
> I would like the compiler to infer that I'm creating a staticArray
> using this:
> 
> int[] myArray = [0, 1].staticArray;
> 
> I don't see why it requires my to only ever use auto.

This does work:

	int[2] myArray = [0, 1].staticArray;

Though it does also defeat the purpose of .staticArray. :-D


> I don't like using auto here.

It's already obvious from the initializer what the type of myArray is,
why would you want to repeat it?  I prefer my code to be DRY.  I almost
never write:

	int[] x = [1, 2, 3];
	MyStruct s = MyStruct(1, 2, 3);
	MyClass obj = new MyClass;

Too much redundant information.  This is better:

	auto x = [1, 2, 3];
	auto s = MyStruct(1, 2, 3);
	auto obj = new MyClass;

The compiler can already figure out the types for me; let the machine do
its job while I focus on more important things. Like actually solving
the programming problem I set out to solve, for example.


T

-- 
LINUX = Lousy Interface for Nefarious Unix Xenophobes.


More information about the Digitalmars-d mailing list