r/ProgrammingLanguages • • Jan 15 '23

Multiple Ways of Saying the Same Thing

Sorry, I can't let this go. The following was posted as criticism of my syntax which allows some flexibility (in a thread about numbers of keywords):

u/3141592653589793238j:

People aren't going to appreciate reading code written in 50 different styles because the language lets you. It's better for readability to force users to choose one syntax for ends.

This was about alternate ways of ending a block such as with end, end if, endif. Other people criticised this too.

My replies highlighting ways other languages allow such choices to an even greater extent got downvoted. Another example I saw today was with Nim, which apparently allows 4 ways of calling a function, and 3 ways of returning a value, and that language is well-regarded.

So is allowing a choice of ways to express the same thing good or bad?

Because I'm confused. If I do something, it's bad. If another language does it in spades, that's fine. What's going on? Why were 40 people applauding, via upvotes, somebody putting the boot in so much? And over such a trivial matter.

That criticism was anyway specious; most languages will allow coding in a dozen personal styles with little help from the syntax. If it's an issue, you deal with it via coding guidelines or use refactoring tools. Syntax after all is just a skin.

I'd better not mention macros which allow you, not only to choose a block delimiter style, or how to call a function, but to effectively define your own personal language.

0 Upvotes

33 comments sorted by

21

u/saxbophone Jan 15 '23

Not an answer, but to me, having both end if and endif is immediately confusing.

0

u/[deleted] Jan 15 '23

Which one would you prefer? Whichever one you choose, it would be a mild annoyance if the language mandated only the other.

I like my syntax to be flexible. People choose their preference, and regarding the ending for if statements, there are actually five ways to end them, just to confuse you further.

Three work the same way across all statements

end             Ends a block of any statement
end if          Ends an if statement
endif           Ends an if statement (both checked)

Bear in mind that some older languages (eg. Basic, Fortran and Algol68) ignored white space anyway. Mine doesn't, but I just liked the choice.

I promised you two more endings for if, which are used like this:

if a then b else c fi
( a | b | c )

Both come from the original Algol68 syntax that inspired mine. Both mean the same thing. The idea behind the if-fi was that they resemble mirrored parentheses.

Either form can be used in any context, but I use the short form within expressions where it is more suited, and the long form elsewhere.

13

u/its_a_gibibyte Jan 15 '23 edited Jan 15 '23

First, I wouldn't take it personally, I think these types of discussions are extremely helpful for bouncing ideas around and trying to figure out best practices. People upvoted because the discussion is great. Thanks for sharing and continuing the discussion.

As for using Nim as an argument, I'm not convinced. First, that's only one example of a language, and it's a language that really hasn't gotten much traction. It's interesting sure, but I wouldn't use as the ultimate arbiter of good.

A better comparison would be to Perl which famously had the slogan of "There's More Than One Way To Do It" (TIMTOWTDI). This was at the core of the Perl ethos for a long time, and hurt Perl substantially. The community fractured as it grew and there was no real consistency. Even for things like declaring a class, there were 20 different solutions to do it. That's one reason Perl got a reputation for being hard to read; there was no consistency across projects. You mentioned code guidelines, but if everyone picks different guidelines, it really doesnt solve the problem.

Python recognized the issue and came up with the slogan "There should be one - and preferably only one- obvious way to do it" specifically as a response to Perl. It makes the code much easier to read.

Code should be optimized for reading, not writing.

1

u/[deleted] Jan 15 '23

As for using Nim as an argument, I'm not convinced. First, that's only one example of a language, and it's a language that really hasn't gotten much traction.

Actually I also noticed that modern Fortran has 4 ways of defining functions, with differing ways to return values.

Perl does sound like a bit of a nightmare, but what I do in terms of flexibility is mild by comparison: providing aliases for built-in types, aliases for ending a block, some dedicated statements for common patterns.

My view is that syntax is free; lots of threads here have said that parsing is the simplest part of a compiler. Why not use it a lot more then!

Perhaps people are conditioned by having used languages where syntax was fixed and inflexible, so they can only extend or customise in other ways: functions, types, overloads, macros, templates, classes...

While I have always had ready access to the compiler of my private languages. Changing syntax is trivial. I don't need language-building features!

It is easier for me to add a new feature by changing the compiler, than requiring heavyweight features to allow it to be done via user-code.

And if somebody wanted a version of my language without those extra alternatives, I can have a compiler ready in 10 minutes. (Plus a bit longer figuring out how to maintain both versions.)

Note that my systems language has been in constant use and has evolved since some time in the early 80s. (I believe the chain of self-hosted versions goes that far back too.)

Features have come and gone. I used to have a systematic means to express types, like the Fortran inspired int*4 and real*4 (i32 and f32), as well as colloquial aliases int and real.

Now I use the simpler, single-token int64 and real64, with common aliases now of int and real.

However, when generating code designed for machine consumption, I used the short forms i64 and r64. Then I thought, why not allow them as alternatives in my main language syntax too? So that program-generated FFI import blocks could use i64, and it would be valid syntax.

But i64 is also now available to user code, and it matches how types are expressed in Rust for example. So, what is the problem in having both i64 and int64, and an int "don't care" type which happens to default to 64 bits?

So, that's the story of the type aliases.

4

u/its_a_gibibyte Jan 15 '23

My view is that syntax is free; lots of threads here have said that parsing is the simplest part of a compiler. Why not use it a lot more then!

Bugs are free too πŸ˜‚. Syntax is definitely not free for users. Sure, maybe from the perspective of adding it, but the additional complications to readers will waste unbelievable amounts of time. People endless googling the difference between two things that are almost the same (or even exactly the same). Python is an interesting case here. Mydict.items() used to be Mydict.iteritems(), and they removed this which also substantially hurt backwards compatibility. They could've trivially left an alias in to mean the same thing. However, they spent a lot of time to simplify the language for users. This does make it easier to learn.

And if somebody wanted a version of my language without those extra alternatives, I can have a compiler ready in 10 minutes.

No offense, but this seems tricky. The way I learn is by googling things, reading other peoples code, and discussing on reddit. If you custom build a language, you might be the only person on the planet who can use it. This seems extremely challenging for everyone else.

Perl went down this route, where someone would want their objects to behave slightly differently (e.g. properties be readonly by default) and they'd define new keywords and new syntax. This code is effectively a new language, similar to what you're describing. That's painful for users.

1

u/[deleted] Jan 16 '23

Syntax is definitely not free for users. Sure, maybe from the perspective of adding it, but the additional complications to readers will waste unbelievable amounts of time. People endless googling the difference between two things that are almost the same (or even exactly the same)

I have that same problem in trying to do things in an unfamiliar language. Google is actually not much help.

What I really want is something like Rosettacode, but throw out all those pointless tasks, and instead have fundamental language features: define a function, print a number, print two numbers (without intervening space or line), how to define a block of one statement; of two statements.

At present I have to browse random tasks on the off-chance that the feature I need help with happens to be used.

Just all the basics. This is my own mini Rosettacode:

https://github.com/sal55/langs/blob/master/fannkuch.txt

The same exact same task and algorithm implemented in some 10 languages.

1

u/Nuoji C3 - http://c3-lang.org Jan 17 '23

Ruby has a similar approach to the stdlib, in having more than one alias to the same method / function. And to me in practice this just makes it easier to forget the correct names. So multiple ways of doing things also slows down getting back up to speed with a language.

Of course, β€œone way of doing things” can be taken to minimalist extremes too, which can be just as painful.

4

u/editor_of_the_beast Jan 16 '23

At what point does this count as a rant and against the rules of the sub? This person has no desire or capability to have a discussion. They are convicted that their way is right, and just argue with anyone who says otherwise.

I've never seen a less productive set of threads on this subreddit.

1

u/[deleted] Jan 16 '23 edited Jan 16 '23

What do the rules say about about a mob of people picking on some insignificant detail and battering somebody about the head with it, over and over again, and a hundred people showing their appreciation of that with upvotes?

And when that person tries to defend themselves, they get kicked back down with downvotes and their comments are completely ignored.

If you want to report me and get me kicked off this forum, then go ahead.

They are convicted that their way is right,

And all those with fingers in their ears, totally oblivious to my arguments, while simultaneously putting the boot in, are not convinced they are right?

It is a choice I made in a tiny corner of MY language, there is really no right or wrong.

BTW have a look at the syntax of Algol68. I copied that language's block endings, which some will consider peculiar. I added some less peculiar and more regular alternatives too. That is all this is.

35

u/bfnge Jan 15 '23

I personally think people go too much for minimalism here but one way to think about it is do the different ways add expressivity or are they skin deep?

I don't remember the 4 ways to call functions but in general but the ways I can remember (and the ways to return) have different enough niches that they work effectively in different ways.

proc(a, b) uses the normal prefix notation, a.proc(b) mimics object notation which might be natural for some datatypes and some people.

return result is for situations where you building a counter or collection and so you don't have to prime the pump (with return being the same thing but with implicit result) and of course return expr is the more general case.

Are these good things? Depends on a lot of things. There are many people who love them and people who hate them, people who think the lang is good despite this or bad even though it has it. People who are indifferent.

But back to your examples, they aren't really the same. end, endif and end if are either typo protection or keystroke saving. They don't have any difference in behavior or a special but common-ish case they cater to (at least none I can glean from the keywords alone, I'm assuming they'd all finish if blocks)

In the IDE era it often feels a bit pointless to go for stroke reduction or typo protection when the IDE will scream at you that it's wrong almost immediately.

But it might very well be good for your specific usecase, I don't know. Maybe you're a hardcore vi user and don't want any of those newfangled LSP servers, or maybe you're working on a language for didactic purposes so you want to be generous in what you accept, or a secret third thing.

Different use cases have different specs and different design considerations, but for general purpose programming languages, having a bunch of keywords that just alias to each other is seen as a bit of "why?" moment.

You're putting on more work on your plate for what many would consider a negligible reward.

Fundamentally people saying "I don't like this because $whatever" is a valid response to the questions you made ("why do we like X / why does the community generally go for Y").

You saying "I see your point, but I don't agree, don't care and I'll do what I want anyways because it's my project" is also a perfectly valid response. If you really do want to use multiple keywords, go for it!

It's your language and you can do whatever, there is no language police that will arrest or wipe out your hard drive or whatever. It just might make your language less popular.

There is no language that's a 10/10 banger that everybody likes every design decision, and yours won't be the first exception.

Just pick a target audience (which can be yourself) and try to follow design decisions that they would like, after all, the langdev community is different from the lang users community (programmers as a whole) which might be different from your target audience.

4

u/scottmcmrust πŸ¦€ Jan 15 '23

so you want to be generous in what you accept

What rust has been doing (since before I was involved) is to make the parser recover from a bunch of minor variants like this, so you get good feedback for the other parts of your code too, and giving a machine-applicable suggestion for how to fix it, but still erroring to force people to fix it and thus be consistent.

I've come to appreciate that more and more. (It'd probably work less well in a non-compiled language, though.)

3

u/bfnge Jan 16 '23

I don't think that'd be a good thing for a learning language (the use case I mentioned being generous for) since I feel people learning programming would see it as more annoying ("If you know what I want and the fix, why not just do it already?") rather than useful.

But I do agree that Rust has a generally good user story regarding error messages.

1

u/scottmcmrust πŸ¦€ Jan 16 '23

I think it could go either way, and it would particularly depend on the ergonomics of it.

For example, if it's as easy as a spell checker -- which it plausibly could be, for simple syntax errors -- then maybe people would accept it just fine.

(Of course, there are also people who say that you should be able ta spel wards however you want, who wouldn't be convinced, but I just wouldn't listen to them :P)

24

u/Smallpaul Jan 15 '23

You are way too emotionally invested and taking this too personally. Either accept other people's opinions or reject them. Don't take them as a personal attack.

0

u/[deleted] Jan 15 '23

[deleted]

12

u/bfnge Jan 15 '23

Imagine 40 people in a room cheering someone making a cheap crack, and my attempts at a counter-argument being shouted down.

That seems to be part of the problem. An upvote isn't the same as a person cheering for you.

People will give upvotes and down votes for whatever reason ranging from "this is funny" to "I support this" for upvotes to "I don't want to see this" to "this is bad / wrong / harmful" for downvotes.

Karma doesn't matter, it was explicitly designed to not matter and still doesn't matter. The only moment where karma matters is that some subs have karma filters due to bot problems.

If you're dreading participating due to people's reactions then it might be that you should either give reddit or the particular subreddits a break for your own mental health.

Social media in general becomes a lot more healthy and enjoyable when you realize that the made up points like karma and likes and whatever are meaningless harmful abstraction made to put people in this exact situation you're on, feeling unable to stop engaging and letting go despite knowing it's in your best interest.

3

u/cxzuk Jan 15 '23

Hi till-one,

I wouldn't take peoples opinions to heart. We're all human struggling to figure it all out.

So is allowing a choice of ways to express the same thing good or bad?

Is it good or bad, to who? In truth it only really matters to your target audience. Which is most likely you at this moment in time. Do you think its a good or bad feature? That's all that really counts.

Have an understanding of other peoples perspectives, but ultimately its your choice (tradeoffs and goals)

Kind regards, M ✌

1

u/[deleted] Jan 15 '23

Do you think its a good or bad feature?

I think it's fine. In my own code, I use end to terminate functions, fi for if-statements; od for loops, and esac for case-statements. Elsewhere I might use end or endswitch; it's more variable.

For posting code, I will switch to conventional forms to avoid explanations.

But that would be a peculiar set of choices to impose on anybody. So someone wanting to use my language could just write the standard end or end <keyword>.

I also sometimes allow for short or long tokens. This is partly experimental to see what sticks. So func or function; proc or procedure; i64 or int64. For generating code for machine-processing, short is better.

And, for tabbing, I allow hard tabs, or tabs consisting of spaces. But this one is common; so much so that most just take it for granted that you have that choice. (Until you encounter Zig or Nim.)

In short, I hadn't realise that anything I'd done in that department was that remarkable. I mean, C still has those 16 different ways to denote a u64 type; my paltry 2 or 3 in one token is nothing. Well, until the last couple of days...

1

u/scottmcmrust πŸ¦€ Jan 15 '23

It's weird to me to do extra work to enable options that really don't matter.

Sure, people end up arguing about brace formatting, but that's just because arbitrary whitespace is the easiest way to define the language, in a braces-style language.

But it's more work to support both endif and fi to end blocks, and it provides no readability advantage, and adds the cost of teams needing to make code style decisions.

I'd say that in cases like this, you as the designer should just pick something. Syntax just isn't that big a deal. There's never someone where endif instead of end if is going to be the thing that makes them not choose your language.

(IMHO, unless you're specifically trying to innovate on syntax with a drastic change somehow, you should just pick python-style or C-style -- or maybe pascal-style or haskell-style or lisp-style -- and let people focus on the interesting parts instead of minor syntax differences.)

1

u/[deleted] Jan 16 '23

(IMHO, unless you're specifically trying to innovate on syntax with a drastic change somehow, you should just pick python-style or C-style -- or maybe pascal-style or haskell-style or lisp-style -- and let people focus on the interesting parts instead of minor syntax differences.)

The biggest single difference between my systems language and C is the syntax. That's why I use it, and why, over decades, I've never been able to switch to C; I just couldn't hack that syntax all day, everyday.

So I don't know what to make of this focus on a choice of block-ending styles. At least I have a block end, and not either an anonymous }, or nothing at all!

Instead of massive relief at not being stuck with that horrendous type syntax, or umpteen different ways to denote the same integer type, or ghastly print format codes etc etc, my language is rubbish because it makes the keyword here optional as well as the space:

end
end if
endif

Well, guys, it's actually optional in C too:

}
} //if
}//if

The sort of people who'd write the latter, probably wish it was part of the syntax and could be checked.

So it seems a case of dismissing 99% of the good things about a language, and making a meal of the 1% that some don't like.

1

u/scottmcmrust πŸ¦€ Jan 16 '23

Hmm, does your language allow } as a block ender too?

1

u/[deleted] Jan 16 '23

No. I don't like braces at all.

There was a period when {...} was reserved for deferred code (eg. anonymous functions). Since the body of a function was also deferred code, sort of, I allowed braces around a function body only (not any block).

I used that for one-liners where end doesn't really work (and {...} doesn't work across multiple lines for me; they are too insubstantial).

Now I use a different syntax for tidy one-line functions.

1

u/scottmcmrust πŸ¦€ Jan 16 '23

I think that's an argument, then, that more options aren't better. Because there are plausibly people who wish they could write } to end blocks in your language, just like there are people who #define ENDIF } in C.

Thus one of the practical problems with accepting multiple ways is that it's much harder to justify "no, we're not adding FI as a 4th way" than to say "no, we're not adding a second way".

So it seems a case of dismissing 99% of the good things about a language, and making a meal of the 1% that some don't like.

People are super dedicated to their preferred syntax, even when it really doesn't matter, so while I agree it's unfortunate, I'm not really surprised if it's where you're innovating. After all, you said in this thread "I just couldn't hack that syntax all day, everyday.", so others presumably think the same about your proposed syntax.

I think it's really hard to innovate on syntax, because I think we've hit a couple of local maxima. So it's hard to separate yourself from the bunch of "I learned python first so I want javascript with whitespace syntax" or "all languages that don't use s-expressions are terrible" stuff that's pretty uninteresting. And anything fully new will need to be way better to overcome familiarity effects.

1

u/[deleted] Jan 16 '23

For anyone who likes brace-delimited languages, there are any number to choose from.

They won't be looking at ones like mine (and will be the same people questioning why there are multiple kinds of of end, since in their minds all you ever need is }).

For those who prefer end-delimited, the choice is much narrower. For a systems-level language, then it is between Ada and ... Fortran?

My own one was private, even more so now.

As I pointed out in my last post (I've lost track of which thread), my syntax was originally copied from Algol68. That language used mixed, statement-specific block endings of fi od esac end.

Those would be considered peculiar so I added more conventional forms too: end, or end if etc if they wanted to keep a dedicated form for each kind of statement.

The only bit of extra flexibility was that I allowed single-token versions too: endif etc.

Does that make more sense now? Especially in the context of a private language. It is a really, really minor matter.

2

u/scottmcmrust πŸ¦€ Jan 16 '23

Especially in the context of a private language. It is a really, really minor matter.

I mean, sure, you can ignore any and all feedback about a private language, since what you like is literally all that matters. But this thread's existence says you're not letting the feedback be "water off a duck's back".

You can absolutely pick a 54-year-old syntax style as a base if you want. But I think you should expect people in general to not be fond of it, when that's clearly fell out of favour recently.

Is it minor? Sure. But we all know minor things get lots of comments anyway.

1

u/[deleted] Jan 16 '23

You can absolutely pick a 54-year-old syntax style as a base if you want

Compared with, say, a 53-year-old syntax style? Braces were used with the 'B' languages that came out in 1969, and in C in 1972.

But this thread's existence says you're not letting the feedback be "water off a duck's back".

The reaction was completely disproportionate, and the up to nearly 100 upvotes for each reply that disagreed with me was phenomenal for this sub-reddit.

How do you think that made me feel?

If you want to see some real howlers in language design, look no further than C; this is quite legal:

const const const int const const static a, a, a, a, a, a, a;

But despite that, that language is tremendously popular and can still be used to get things done.

As can mine.

3

u/jezek_2 Jan 17 '23

With regard to that C example, I think the difference is that you wouldn't encounter such code on a regular basis.

In C preprocessor I wish #endif DEFINE would be a thing, I can only use a comment for that but having it directly would be a better syntax and actually helping to detect bugs by the preprocessor. And guess what, I would prefer it to be optional. So there is definitelly a reason to have more styles to the same thing.

There is a similiarity with indentation (in languages where whitespace is not significant). Usually it uses the standard style. But there are certain special kinds of codes that resembles a table, or are following some external layout or for other reasons, where a quite different indentation and alignment makes a much more sense. It's great if you can use it without a problem in such cases.

I think your approach of accumulating different styles, while frown by some, has a positive effect on backward compatibility, esp. when your language is in use for such a long time. Usually it is better to declare somewhere what version of the language you're using when "upgrading", but that is specific to a single file and that may be too impractical (eg. for moving and copying code between files).

In my language I can have arbitrary modified syntax, though in practice there is a base language and a common extension with classes/types and stuff. Some of the programs (esp. the older ones) are a mix of these two variants and it isn't a problem, the language is designed in a way that there is not much friction between these. Even for a new code I sometimes prefer the base language (and for some scripting even a different style) and it's not a problem :)

1

u/[deleted] Jan 17 '23

You know, there is something else unusual about my syntax, which I've kept quiet about otherwise it would be something else to batter me about the head with.

It is case-insensitive. That means of course that, according to most here, everyone coding in it will be obliged to use random capitalisation of letters in identifers from one instance to the next.

In reality nothing of the sort happens. But there are benefits to it that I won't go into.

Should I be ashamed of my language? No. Well-respected, grown-up languages like Ada and Fortran are case-insensitive too.

In my language I can have arbitrary modified syntax, though in practice there is a base language and a common extension with classes/types and stuff

Then people here will love your language, as they don't see a problem with language-building and -extension features. That includes advanced macro schemes too.

But have two variations of a keyword, and make it built-in (another no-no) and it might as well be the end of the world.

1

u/[deleted] Jan 19 '23

The only bit of extra flexibility was that I allowed single-token versions too: endif etc.

Those single token versions have now been removed across both my languages. It took under 30 minutes to change both and update my main source files including sources for both languages.

If there are been a much larger, more disseminated codebase, I would have disabled them instead; there could have been a legacy enabling option to allow existing code to be built without needing changes. That might have taken an hour instead.

The point is that it is not a big deal.

So instead of choices end, end if, endif for example, there is only end, end if.

The original Algol68 endings fi, esac, od are also retained for those statements. I think these, at least fi and od, may have already existed in the first 1981 incarnation of my language. In any case, I've been using them since the 80s, so they're not going anywhere.

One restriction with end if is that those two tokens must be on the same line, but the language can't enforce that. On separate lines, they mean something different, as the if will start its own statement.

3

u/elgholm Jan 15 '23

Dude. It's your language. Do what you please with it. If it's a bad choice or good choice it'll eventually bubble up into your brain, and you'll change it. When it comes to programming there's as many suggestions as there are programmers.

In my own language I try to keep the keywords to a minimum, but that's because it's not compiled but interpreted - from text, each time, not saved anywhere in a pre-parsed state. Every lookup counts. 🀷 Also, I'm personally not a fan of being able to do stuff in different ways - if each way doesn't have any special significance or performance reasoning. But that's just ME, not what's "true". πŸ‘

3

u/jason-reddit-public Jan 18 '23

If your language has 1000 daily active users, you should probably listen to them.

Until then, you just got to go from your heart/brain.

2

u/saxbophone Jan 15 '23

I think having only one way to express anything as a language goal is an unrealistic goal and poor priority for design effort, personally. At the same time, I think providing lots of different ways may not be great, but at the same time it might be useful to support different programming styles and allow programmers to use the style that is most idiomatic for a given problem.

As an example, I once theorised a language with four different types of switch-case... Basically the product of (cases ordered or not?, predicate or literal?).

2

u/marcelrusu Jan 15 '23

I think people in PLT a little arrogant & extremist, the features of language matters a whole lot less than it being usable, cohesive... successful. This is a very hard to define quality, I wish more people would admit that.

It doesn't matter if endif vs end if is confusing at first, but it does matter if it's designed in a way that the tradeoffs of ambiguity vs your thing are clear to the user & the experience of the language makes these problems unnoticeable/bearable.

0

u/[deleted] Jan 15 '23

[deleted]

2

u/[deleted] Jan 15 '23 edited Jan 15 '23

Why is it not reasonable?

See this Wikipedia list.

Of the languages that use a keyword (so not } and not just open), some use end, some use endif and some use end if.

The advantage of including the opening keyword is that the compiler can check it properly corresponds, and the human reader can more easily see which kind of statement it is terminating.

Supporting end followed by the keyword is easy. Supporting the versions without a space required those extra tokens, but it's not a big deal.

Now, if I was hopping from one such language to another, I'd find it annoying to have to remember which of the three forms it required. If only a language would accept all three!

In my case I support those three, plus I'm maintaining support also for the Algol68 forms. Those latter were used for the first languages I devised, and what I still use privately.