Skip to main content

Questions tagged [syntax]

For questions relating to the syntax, or overall structure, of programming languages.

Filter by
Sorted by
Tagged with
4 votes
1 answer
161 views

Prior art for concatenative array language?

I am probably lazy so I don't feel like thoroughly designing and implementing a new language. But maybe it already exists? Do any programming languages exist with the following traits? no need for ...
Марат Рамазанов's user avatar
2 votes
1 answer
271 views

How is a python namespace implemented in terms of memory under Cpython implementation? [closed]

I am confused about the implementation of a global namespace in python . How are variable names mapped as keys to the objects they reference as values ,since namespace is implemented as a dictionary? ...
Silah's user avatar
  • 23
19 votes
5 answers
4k views

Why is array access not an infix operator?

The typical syntax for accessing an array (or list, map and similar data structures) at a specific index is a[i]. I believe C first introduced it as syntax sugar, ...
linux_user36's user avatar
17 votes
7 answers
3k views

The static keyword and clarity in language design

Across languages that use the word static as a keyword or reserved word, I have observed it to mean: "This variable, despite being declared locally, shall be ...
Karl Knechtel's user avatar
6 votes
0 answers
231 views

What was the first language to use backslashes as escape characters in string literals?

I assume that C didn't originate the idea that, for example, the sequence \t inside a string literal should mean a tab character, that ...
Karl Knechtel's user avatar
2 votes
1 answer
277 views

What are the tradeoffs around supporting Unicode keywords and tokens?

Is the mass adoption of Unicode tokens as operators in general-purpose programming languages ​​a good idea? How acceptable is such a language to ordinary users and developers? Background I want to ...
Aster's user avatar
  • 3,238
7 votes
2 answers
559 views

Why implement function syntax as `f a b` or `f: a b` instead of `f(a,b)`?

Sorry if I am not using the correct terminology here, I'll correct it if it turns out to be that way. Programming languages such as Python or Mathematica typically have function syntax implemented as <...
CrSb0001's user avatar
  • 183
17 votes
0 answers
422 views

What impact do type sigils have on programmers?

Some languages, such as BASIC (STRING$), Perl ($scalar, @array, ...
Michael Homer's user avatar
  • 13.1k
2 votes
1 answer
349 views

How would you implement an auto-correct feature for misspelled class attributes?

Suppose that we are working with an object oriented compiled language, such as somthing C-flavored or Java-flavored. There is a class named string ...
Samuel Muldoon's user avatar
3 votes
0 answers
139 views

What are some syntax options for wildcard matching? (+ extensions)

By "wildcard matching" I mean the following: * matches zero or more of any characters. E.g. B* matches any string ...
CoffeeTableEspresso's user avatar
10 votes
3 answers
486 views

What should be the precedence of the bitwise operators relative to each others?

In C, the relative precedence of bitwise operators is as follows, from high to low precedence: ...
WhiteMist's user avatar
  • 281
41 votes
8 answers
17k views

Why is almost every programming language made in English?

Every programming language I know (Java, C++, C#, Python, etc.) are all made in English. That is, you can't, for example, type imprimir("hola") instead of ...
Daemons's user avatar
  • 515
6 votes
1 answer
357 views

How to design interfaces to mimic haskell-like type classes in an object oriented language?

A problem I sometimes run into when using a language like TypeScript or C# is how they lack a perfect analogue to Haskell's typeclasses. Let's use Haskell's Functor ...
Kilian Kilmister's user avatar
6 votes
2 answers
402 views

Why does python allow single-line compound statements?

I came across this question on Stack Overflow and it got me wondering... why did Python choose to allow single line compound statements? Python has significant whitespace, and it seems like the parser ...
Jared Smith's user avatar
-2 votes
3 answers
229 views

How about support function return itself? [closed]

It seems that no language supports this feature: Define a function that can return the function itself. This function will continue to be called and continue to return itself. For example: ...
Aster's user avatar
  • 3,238
7 votes
6 answers
937 views

What are the consequences of allowing decimal-point-less number literals to be interpreted as floats?

In some languages, a number literal's type can be inferred from nearby expressions. For example, 1u64 + 2 might give a u64 value ...
Rydwolf Programs's user avatar
5 votes
1 answer
220 views

Should bitwise operations have dedicated operators? [closed]

Many programming languages have built-in support for bitwise operations, often using C's syntax: ~ = NOT & = AND ...
dan04's user avatar
  • 1,969
5 votes
1 answer
178 views

Possible ways to determine reach of implicit lambda expressions

When defining an inline function, even the shortest way to do so usually requires naming its argument (unless you're going for the point-free style and you have an expression that returns a function). ...
Lazar Ljubenović's user avatar
2 votes
1 answer
303 views

What if all static methods in Java or C# could be extension methods just by default?

C# 3.0 introduced extension methods to "enhance" behavior of existing types without interface bloating to avoid modifying/breaking existing interfaces. This was the first time I learned of ...
terrorrussia-keeps-killing's user avatar
26 votes
2 answers
3k views

Studies on learnability of braces vs. indentation for code blocks for beginners?

The discussion whether using indentation for code blocks is better or worse than using braces is an old one, but I don't want to rehash that discussion here (for reference, there was a fairly recent ...
Schmuddi's user avatar
  • 363
2 votes
1 answer
1k views

Why do we put imports at the top of files? [closed]

Most of the popular programming languages I know of either require or strongly encourage import statements to be at the top of the file, before any of the ...
Silvio Mayolo's user avatar
6 votes
1 answer
186 views

What's the benefit of using different tokens for accessing nested namespaces/modules versus properties?

In JavaScript, accessing items from a module is done using ., e.g. moduleBar.moduleFoo.functionFoo, which looks exactly the same ...
Lazar Ljubenović's user avatar
31 votes
11 answers
19k views

Why do so many programming languages not have a "built-in" way to do simple math functions?

Note 1: My question is not about the factorial function. It's about "simple math functions" that high-school level pocket calculators can do, but most programming languages cannot do without ...
Nike Dattani's user avatar
22 votes
4 answers
5k views

Why do many template languages have `for-else` statements?

I've noticed that many template engines have a mechanism for detecting that a loop is not occurring. Although their names and syntax vary, they all have this similar structure. For example: Jinja <...
Aster's user avatar
  • 3,238
13 votes
7 answers
4k views

Are there any situations in which it would make sense to return a never type?

Some languages (Rust is the first one that comes to mind) have a "never" type. This is represented in Rust as !, and represents a function that never ...
Ginger's user avatar
  • 2,629
31 votes
3 answers
12k views

Why did Rust require macro names to have an exclamation point at the end?

Why did the designers of the Rust programming language require that macro names have to end with an exclamation point? I observe that both Common Lisp and Emacs Lisp language variants do not appear, ...
bgoodr's user avatar
  • 413
17 votes
6 answers
9k views

Does Python's semicolon statement ending feature have any unique use?

Python does not usually use explicit line-ending characters; the parser can almost always figure out where a statement ends from the positioning of newlines. However, Python's syntax allows you to use ...
Ginger's user avatar
  • 2,629
17 votes
2 answers
3k views

How do lexers/parsers distinguish between nested generics and bitshifts?

The lexical grammar of Java has a special case for the the > character. Normally, tokens are formed based on the longest-match rule, so that an input string of <...
kaya3's user avatar
  • 20k
3 votes
4 answers
423 views

What evidence exists on using & and | as logical operators instead of && and ||?

I’m working on a small, dynamic language that isn’t going to include bitwise operators so I was thinking it was a bit unnecessary to use && and ...
user avatar
4 votes
6 answers
2k views

Why tag function definition with def, fn, fun, func or function etc?

What makes it hard for compilers/interpreters that we need to tag the function definition with keyword fn/fun/func/function? I can understand that types for numbers: int, int32, float32, float64... ...
Anubhav's user avatar
  • 173
12 votes
2 answers
1k views

Why do many languages use square brackets for array indexing?

A lot of languages use square brackets for array indexing, and round brackets (also known as parentheses) for function calls. For example, in C: ...
G. Sliepen's user avatar
  • 1,016
45 votes
6 answers
13k views

Why do programming languages use the asterisk * for multiplication?

Having had very little math(s) education I'm trying to bring myself up to speed for university, which currently involves teaching myself the times tables, where X ...
Hashim Aziz's user avatar
27 votes
6 answers
12k views

Why do programming languages use delimiters (quotes) for strings?

Almost every programming language requires strings (or char* or equivelent) to be marked with quotes. Few languages allow other delimiters, many languages allow ...
Safwan Samsudeen's user avatar
3 votes
0 answers
89 views

Is it more readable to declare the return type of a function on the left side of it's name? [duplicate]

A lot of C-like programming languages (Java, C#, ...) use the following syntax for defining functions: returnType functionName(parameters...) { } Is there a ...
tigrou's user avatar
  • 131
8 votes
5 answers
795 views

Declaring infix operators like Haskell's in other languages?

Haskell has support for declaring custom infix operators, including their precedence and associativity. In addition, any identifier can be used as binary infix operator by placing it between ...
Christian Lindig's user avatar
3 votes
4 answers
289 views

Common postfix representations of pointer/reference operations

In some C-based languages (including C/C++ themselves and Rust), taking pointers/references and dereferencing is done with prefix operators & and ...
abel1502's user avatar
  • 2,537
10 votes
1 answer
2k views

In Python, why isn't it a syntax error when a list of strings is defined without comma separators?

When coding in Python, I found that defining a list of strings without separating the strings with a comma is not a syntax error. When running this code: ...
Redz's user avatar
  • 1,076
2 votes
1 answer
238 views

What are the exact requirements of not requiring forward declarations everywhere?

Some languages like C and C++ require defining the names before using them, though the definition could sometimes be only a header specifying something is a struct or function without the body. Some ...
user23013's user avatar
  • 2,578
3 votes
1 answer
233 views

What syntactic ambiguities can arise in a language with optional semicolons for statement or expression separators?

What syntactic ambiguities can arise in a language with optional semicolons for statement or expression separators? Let's say that that the syntax for this language generally follows the C syntax and ...
WhiteMist's user avatar
  • 281
3 votes
3 answers
234 views

What are pros and cons of adding special syntactic sugar for decorators? [closed]

Some languages have syntactic sugar for decorators (like Python), but some languages do not (like Go). PSL Some languages do not have decorators at all. So, what are pros and cons of syntactic sugar ...
чистов_n's user avatar
18 votes
7 answers
4k views

How can the language or tooling notify the user of infinite loops?

I'm trying to teach a friend to code in Python. I've noticed that whenever they write a while loop with an integer increment, such as the one shown below: ...
Redz's user avatar
  • 1,076
3 votes
1 answer
100 views

Languages with source include (AST or concatenated) [closed]

Some languages allow you to import local (file system) files normally via some directives like import: In Dart: ...
Hydroper's user avatar
  • 1,017
14 votes
4 answers
3k views

Could function parameters be placed inside names?

While in the shower thinking about my code, my mind went to C#'s type parameters, and I wondered what stops the type param from being placed in the middle of the function name like this: ...
flumperious's user avatar
32 votes
10 answers
9k views

Avoiding student confusion about the meaning of `x == a or b`

I'm designing a language intended to teach kids and other beginners how to program. It's just a fork of Python with a few extra features to make it easier to learn. I've noticed students make one ...
mousetail's user avatar
  • 8,531
5 votes
1 answer
145 views

Do let bindings need an assignment operator for disambiguation?

Let's say I want to allow (conservative) let bindings, with optional type ascription. Most imperative languages would put a = or ...
user avatar
5 votes
1 answer
201 views

What sort of "syntax error recovery" is possible for this indentation based language?

I am thinking of how to write the parser/compiler so it works as a VSCode Language Server Extension, so I can have it show syntax errors, do autocomplete, and other things, in VSCode. One thing that I'...
Lance's user avatar
  • 705
9 votes
4 answers
520 views

What are the advantages of keyword based syntax versus punctuation based syntax?

Some languages such as Lua and Assembly Basic use keywords for syntax. This includes spelling out words such as do and end in ...
CPlus's user avatar
  • 8,753
2 votes
3 answers
247 views

Pros and cons of generalized `nil`-coalescing operators

Many languages extend their "indexing" operator . to a nil-coalescing variant ?. to deal with indexing chains such as <...
Luatic's user avatar
  • 330
6 votes
6 answers
376 views

Ways to have operators for both normal and floor division

I want to have an operator for true division (like / in python) giving a float as the result and floor division (like // in ...
MarcellPerger's user avatar
-4 votes
1 answer
257 views

What are the disadvantages of including foreach loops? [duplicate]

Yes, FOR loops. Those great things. There are good for shortening code. But there may be downsides I'm not aware of. I'm referring to Python style FOR loops. So, what are the disadvantages of ...
Starship's user avatar
  • 1,336