r/ProgrammingLanguages • u/Xadartt • 13d ago
Programming in English
pvs-studio.comSome thoughts on why natural language still can't replace code
r/ProgrammingLanguages • u/Xadartt • 13d ago
Some thoughts on why natural language still can't replace code
r/ProgrammingLanguages • u/Athas • 13d ago
r/ProgrammingLanguages • u/SeaInformation8764 • 13d ago
Hello, I spent a little bit of time throwing together a README for a programming language that I am working on after repeatedly abandoning previous projects. For this project, I really wanted to start by focusing on the type system and I thought of some cool ideas. I have a lot of the implementation details worked out, but I wanted to know if anyone had thoughts!
(repost because I didn't know I couldn't upload GitHub links)
Below is the README pasted from my GitHub, you can also view it at ephf/boxc for better Markdown parsing.
boxc is a C-like language transpiled into C.
[!IMPORTANT] This language is in active development and has no current releases, below are some ideas / dev logs and current progress. Below code examples, you will see checklists on what is implemented and what is not.
Although it may not look like I have done much in the development of this language, I have made a couple of other unfinished languages that I have learned from. See,
The main idea for this first round of development is focusing on the type system, generics, and overloading. In order to do this, I am trying to build out a tuple type, similar to C++.
struct tuple<...>;This code declares a tuple structure without a body, it cannot be used in this state to define a variable,
tuple<> x; // error: tuple<> has no bodyThe tuple struct will have two main overloads that will create a linked-list structure in compile time.
struct tuple<<First, Items...>> {
First value;
tuple<Items> next;
}
struct tuple<> {}[!NOTE] Defining a tuple using
<<>>instead of<>is a shorthand which will create an overload. Normally overloading requires type arguments and a generics declaration, like the following:This can also be used to mix and match type arguments and generics,
Below is an example of what the compiled code would look like,
tuple<i32, char, usize> x;
struct tuple {};
struct tuple0 {
size_t value;
struct tuple next;
};
struct tuple1 {
char value;
struct tuple0 next;
};
struct tuple2 {
int32_t value;
struct tuple1 next;
};
struct tuple2 x;You could implement a function similar to std::get<size_t> in C++, however there are a couple of things I wanted to implement that would make this easier.
Here I have defined a trait for the field_access operation or .
namespace std::operator {
trait field_access<Accessor> {
Field field_access<Field>(self, Accessor);
Field field_access<Field, Accessor accessor>(self);
}
}The field_access trait has two functions that can be overridden. The first one accepts any expression, and the second one, which takes precedence, takes any compiler constant expression.
We can implement this trait in the tuple type to make it easier to select specific tuple values.
struct tuple<First, Items><Index : usize, First, Items...>
: std::operator::field_access<Index>
{
First value;
tuple<Items> next;
inline auto field_access<First, index><Index index>(self)
index ? next.field_access<auto, index - 1>() : value;
}This will allow us to use the . operator to get a specific element in our tuples at compile-time,
tuple<i32, u32> x;
auto y = x.0;
auto z = z.1;
assert typeof y == i32;
assert typeof z == u32;Overall, I think one of the main things I want in this language is for a lot of the language features to be implementable from within the language itself instead of relying on syntactic sugar.
Similar to JavaScript's ?. operator, I wanted to create an easy way to interface with nullable values and optionals. Below is a definition for an operator override using ? as an operator.
namespace std {
trait nullable_coalesce<NonNull> {
std::tuple<bool, NonNull> nullable_coalesce(self);
}
}If we have a value that implements this trait, we can use the ? operator to conditionally search through a hierarchy of values.
[!NOTE] You can differentiate the
?nullish coalescing operator from the?ternary operator because the nullish coalescing operator needs to be followed by a postfix operator like.or().
struct MyStruct {
int field;
}
int? get_field<T : std::nullable_coalesce<MyStruct>>(T maybe) {
return maybe?.field;
}
MyStruct* not_null = &{5}; // referencing an rvalue will stack allocate its value
auto x = get_field(not_null);
auto y = get_field(null); // null is a keyword similar to nullptr, but it can also be used as a type
assert *x == 5;
assert !y;int? is syntactic sugar for std::option<int>. Before we write option, there are a couple of traits it needs to override,
namespace std::operator {
trait dereference<Type> {
Type dereference(self);
}
}
namespace std::trans {
trait from {
Self from<From>(From);
}
trait into {
Into into<Into>(self);
}
}Now we can write option,
namespace std {
struct option<Type>
: operator::dereference<Type>, trans::from, trans::into
{
Type || null data;
inline Type dereference(self)
self.data.(Type);
inline Self from<Type>(Type data)
Self { data };
inline Self from<null>(null)
Self { null };
inline bool into(self)
self.data.is<Type>();
};
}Overall, even for syntactic sugar, there will be definitions inside of std that are being referenced.
r/ProgrammingLanguages • u/Trave11er3427 • 14d ago
for those that compose and craft compilers, do you find the results better and more satisfying for you if the compiler you work on is permissive/optimistic or strict/pessimistic?
permissive/optimistic here means that the starting point is the compiler assumes the line of code that it is parsing/evaluating is probably ok but needs to pass some checks before translating to the target backend? (this is “the compiler is your friend” approach)
strict/pessimistic here means that the starting point is the compiler assumes the line of code that it is parsing/evaluating has something wrong and its job is to discover that wrong thing, and it is disappointed when the line passes all checks before translating to the target backend? (this is “the compiler is the teacher we’ve all had at one point in our life where they assume you’re going to do something bad as soon as they’re not looking” - and they’re not wrong)
obviously there has to be some balance here, but i’m curious, what has been your experience with these two approaches?
r/ProgrammingLanguages • u/naharashu • 14d ago
r/ProgrammingLanguages • u/mttd • 15d ago
r/ProgrammingLanguages • u/Low_Lawyer_5684 • 15d ago
Hello everyone,
Im developing a small hobby scripting language, for embedded applications. It was started as a PHP8 clone, but now it is not fully compatible with Zend PHP.
I would like to get a feedback on language feature Im experimenting with.
It is about type conversions (type casts)
The basic idea is to allow any conversions, but track conversions that may indicate a programming mistake (allowing a bad input to reach calculations is considered a programmer mistake).
I.e.:
Instead of immideately throwing an error or silently accepting the conversion, we can mark the resulting
value as unreliable.
This metadata (a flag) belongs to the value itself (not to the variable). Copying a value preserves the flag, and operations consuming an unreliable value propagate it to their results. 'Consuming' means using the value.
Example of the unreliable flag propagation:
Values can be tested with built-in language construct is_reliable(...);
There are pseudo-types unreliable and reliable which allow this flag manipulation:
Normally program continues executing regardless unreliability of values used.
However, you can explicitely require reliable values in a particular code section:
Reading an UNRELIABLE value inside a reliable block throws an exception.
The idea is to combine the idea of dynamic typing with the ability to enforce stricter guarantees where needed.
I'm aware that propagating unreliability through subsequent calculations is not the best way to detect a programming error at the exact point where it originally occurred :).
By the time the value is consumed, the actual source of the problem may be far away, yes.
I'm interested in whether the benefits outweight this drawback.
A fast-fail mode is also allowed: we want exception but we do not want to catch it:
Examples above are all about strings and numbers, but this mechanism is suggested for all types (hashmaps aka php arrays, float, boolean values, class instances):
What do you think about this approach?
In particular:
Thank you!
r/ProgrammingLanguages • u/mttd • 15d ago
r/ProgrammingLanguages • u/mttd • 15d ago
r/ProgrammingLanguages • u/mrpro1a1 • 17d ago
Hello
I have already released Ring 1.28
Ring is a dynamic language with lightweight implementation like Lua but with more features like Python/Ruby. I created it because I was looking for a Visual FoxPro replacement but was not satisfied with many other languages that I tried. The development started in Sept. 2013, and Ring 1.0 is released in January 2016, and I continued developing it as open-source project for over 10 years. I used to get feedback about the language through this group which contains over 3,000 topics.
So, here is what Ring is trying to do
(1) Keeping the implementation simple and small (The KISS Principle) that one programmer can study/understand in short time, but still a powerful and practical dynamic language with many useful programming paradigms.
The motivation behind this principle: Lua comes with small and fast implementation, but it misses many features provided by default in Python/Ruby. on the other hand, both of Python/Ruby requires different implementation to be used in places where Lua can be used directly, that's why there are projects like MicroPython and mRuby.
In Ring it's the same implementation everywhere. To be able to achieve this we used a custom implementation way and design decisions explained in this paper. So, In Ring, we have extreme portability, it's written in ANSI C (26 KLOC includes the Compiler, The Virtual Machine and 228 standard function), where the same implementation works on Desktop (MS-DOS, Windows, Linux, macOS), Mobile (Android, iOS) & Microcontroller (Raspberry Pi Pico).
(2) Syntax Customization: I am not a native English speaker, and I started programming at 10 years old (Three decades ago), It was a difficult journey for me at that time, I was studying English and Programming at the same time, I used to do translation from English to Arabic using a printed dictionary where I have to search for words meaning and used to spend a complete day just to read one page from my CA-Clipper programming book (for MS-DOS). Ring allows dynamic translation of language keywords/operators and supports multiple syntax styles (Similar to C, Ruby & Basic). For large/serious projects using a code formatter we force a specific style, but the point from this feature is to give each programmer the ability to write code in his native language.
(3) Declarative/Natural Language Programming (Developing Domain-Specific Languages): Ring extend OOP with new simple features that enable designing DSLs that looks like QML, SQL, COBOL, Supernova, etc. in short time. such a feature if used correctly provides advanced abstraction levels that are fun to work with.
(4) Batteries Included + Simple IDE + Form Designer: Something like VB6 era because I am coming from a Visual FoxPro background, but in Ring we can use Qt (We have packages for Qt5 and Qt6 too), and Ring supports Qt for Desktop/Android/WebAssembly, So you can open Ring IDE, design a form, run you app on Desktop, export it as Qt project for WebAssembly and run it in the browser or export it for Mobile and run it on Android. Compared to Python, Ring supports Qt for Android/WebAssembly many years before Qt company do this for Python. The reason is the principle (1), being a lightweight language with simple implementation.
(5) A love message to Visual Programming Languages: Ring Compiler/VM code is generated using my PWCT visual programming tool that I developed starting from Dec 2005. So, one of the goals was a practical project that I can develop using PWCT. After using PWCT to develop Ring, I developed PWCT2 using Ring as an example about what Ring can do. This research paper explains PWCT2 and its improvement over PWCT.
(6) Memory Management: It utilizes a deterministic, safe, and flexible scope-based memory management system that incorporates escape analysis and optional reference counting with cycle detection.
Thanks
r/ProgrammingLanguages • u/FastKnowledge_ • 17d ago
I’m building Duck, a statically typed, compiled language for game development. I’m using it to write Quaxel, my game engine, and Hellfeather, a Diablo II-inspired action RPG prototype. One of the more contentious ideas in Duck is letting the compiler infer which operations can run concurrently. I lean toward giving it that freedom, and I’d like criticism of that choice.
Here’s a small example from a Quaxel test. Each session has its own frame counter and running flag.
QuaxelSession first()
QuaxelSession second()
first.Begin()
second.Begin()
first.Advance()
first.Stop()Begin() resets a session’s frame counter and marks it as running. Advance() increments the counter if the session is running. The order of first.Advance() and first.Stop() matters. Swap them and you get a different frame count. But suppose the compiler can prove that second.Begin() touches only the second session. My instinct is that writing it on the line above first.Advance() shouldn’t, by itself, require one to finish before the other starts.
These calls are tiny. I’m using them because the dependency is easy to see. The case I care about is two expensive updates in the same frame. Even if overlapping them preserves the result, it can still change frame time and make a performance problem harder to reproduce.
If you think concurrency should require an explicit opt-in, what’s a case where you’d want that guarantee even though the compiler could prove the work independent? That’s the kind of example I’d like to test Duck’s design against.
r/ProgrammingLanguages • u/Sensitive_Mountain97 • 18d ago
I'm creating a host-embedded, minimal, beginner-friendly programming language as a replacement for Lua. This language is really human readable, English-like and beginner friendly, with automatic memory management, automatic parallelism, a fantastic and helpful compiler inspired by Rust, and other things. The biggest question I have is whether I should choose 1-based indexing or 0-based indexing?
r/ProgrammingLanguages • u/naharashu • 17d ago
.
r/ProgrammingLanguages • u/Athas • 19d ago
r/ProgrammingLanguages • u/Usual_Office_1740 • 19d ago
r/ProgrammingLanguages • u/thunderseethe • 20d ago
r/ProgrammingLanguages • u/mttd • 20d ago
r/ProgrammingLanguages • u/yolosuperboss • 20d ago
I was watching tsoding's crust stream and I thought it would be so funny if I extended c to have generics.
The way I did this was by extending the syntax of c with the classic rust angle brackets to define generics and then during transpilation do some name mangling to monomorphize the generic code.
Here is the result of that abomination:
#include <stdio.h>
// you can define your own operator in fortran .op. style with a trait
trait<T> DotP {
// for parsing reasons any dot-op must have whitespaces around it in any context
T .dot. (Self self, Self other);
}
// using a very similar syntax to rust, you can add generics to structs
typedef<T> struct {
T x;
T y;
T z;
} Vector<T>;
// and by appling the trait to your struct (with generic parameters)
// you can define what your operator should do.
impl<T> DotP<T> for Vector<T> {
T .dot. (Self self, Self other){
return self.x * other.x + self.y * other.y + self.z * other.z;
}
}
int main(void) {
// by concretly defining which type you want to use as the generic
// a c struct with that/those type(s) is genenerated
Vector<float> fv = {1.0, 2.0, 3.0};
printf("Dot product of fv^2: %f\n", fv .dot. fv);
Vector<int> iv = {1, 2, 3};
printf("Dot product of iv^2: %d\n", iv .dot. iv);
}The generated c code looks something like this (I have actually implemented this transpiler, perhaps a true indicator of joblessness):
/* Generated by typedc. */
#ifndef TYPEDC_SIMPLE_GENERICS_H
#define TYPEDC_SIMPLE_GENERICS_H
#include <stdio.h>
typedef struct float_Vector float_Vector;
typedef struct int_Vector int_Vector;
struct float_Vector {
float x;
float y;
float z;
};
struct int_Vector {
int x;
int y;
int z;
};
int main(void);
static inline float float_dot(float_Vector self, float_Vector other);
static inline int int_dot(int_Vector self, int_Vector other);
int main(void) {
float_Vector fv = {1.0, 2.0, 3.0};
printf("Dot product of fv^2: %f\n", float_dot(fv, fv));
int_Vector iv = {1, 2, 3};
printf("Dot product of iv^2: %d\n", int_dot(iv, iv));
}
static inline float float_dot(float_Vector self, float_Vector other) {
return self.x * other.x + self.y * other.y + self.z * other.z;
}
static inline int int_dot(int_Vector self, int_Vector other) {
return self.x * other.x + self.y * other.y + self.z * other.z;
}
#endif /* TYPEDC_SIMPLE_GENERICS_H */r/ProgrammingLanguages • u/coolSakura • 20d ago
This might sound like a super dumb question, but I did not want to ask Chat gpt and I wanted to ask an actual human,
but why if the first for a church pair , like has this abstraction
λp. p true and not just true.
Is it because its supposed to like take a pair as an argument and spit out the first , and thats it? cause if it were just true it would still behave the same
sry for the dumb question lol
r/ProgrammingLanguages • u/mttd • 21d ago
r/ProgrammingLanguages • u/Nuoji • 21d ago
I think I need to write a blogpost about why I deliberately nerfed dependency fetching. Why it's `c3c project fetch raylib sdl3` and not just `c3c project fetch` when the project has enough information to get them automatically.
r/ProgrammingLanguages • u/Inconstant_Moo • 22d ago
Pretty much all successful general-purpose programming languages were thought of by someone with a particular use-case in mind, or even just one particular use. They became successful because in trying to do whatever-it-was really well, the authors hit a larger target than they aimed for, and the more successful they became, the more this is true. Some examples, in alphabetical order:
malloc in exchange for an inner loop that goes brr.And then there's the obvious outliers:
Some things worth noting:
There are two kinds of programming languages, those written for the author, and those written for other people. And in the second case, the other people are always dumber than the author, who is talking down to them. BASIC wasn't designed because Kemeny and Kurtz needed BASIC. BASIC was designed because Kemeny and Kurtz thought that liberal arts graduates needed BASIC, because what would make things simple for their muddled little heads is a language where all values are passed by mutating global state, which is like having a bicycle for beginners where instead of having training wheels you douse it in gasoline and set it on fire.
So you will notice that none of the things on the list that are used as easy languages for n00bs were designed for that. Python was designed for Guido van Rossum to do systems programming. Lua was designed for engineers and geophysicists. JS ... * gestures broadly at the internet *. They were designed, in fact, to be ergonomic for clever people to use, and it turns out that exactly the same things make languages ergonomic for everyone to use, and that more people are clever than was previously supposed, including liberal arts graduates.
(The fact that > 50% of indie language projects are "C/C++ but better" is because the indie langdevs are all trying to scratch the same itch, they're all trying to write the systems language that they wish they could code in. These are languages written for the authors, where the authors are all very similar people who want similar things.)
The other thing that leaps out at me from my list is that the "classic" functional languages, the Lisp and ML families and Haskell, all came from math people wanting to do hard math things as their paradigmatic use-case, and anyone wondering why functional programming hasn't conquered the world yet should think about that.
(I of course have been thinking about that, and although it is premature to put Pipefish in an article about successful languages, making an FPL for writing CRUD apps has produced an language that hits different, and which can in fact be used for all sorts of cool things besides that. Watch this space for the announcement of my front-end web framework.)
r/ProgrammingLanguages • u/PhosXD • 21d ago
I recently just dropped raw-pointers in my interpreted language in favor of a path-based reference type which always gives `none` if the path ever becomes invalid, unlike a pointer which would cause unexpected issues or crash the program.
Now my question is... am I missing out on anything by eventually removing the pointer type entirely? In a sand-boxed language like Ity where everything is tightly controlled & you cant really access the underlying memory of anything, does it make sense to keep pointers to values? Doesn't a path do everything you need it to? You can access storage cells just the same but it's just safer, or am I mistaken.
The idea here is to make a truly 100% memory safe design, so that you couldn't corrupt or mess with the memory even if you wanted to, but you also get to pass around references to values (which is rather required for a language that has a strict copy-everything rule).
Let me know how you would go about designing a system that can pass around references while maintaining an unbreakable wall between the program & it's memory. The way I handle it is very simple, you can only reference values that are stored as a variable somewhere or is a variable nested somewhere inside some container. This means things like temporary values cannot be referenced as they have no storage cell, which I believe is one difference between path-refs & pointers.
Another big part of my design is that everything is copied, everywhere. Passing an argument to a function copies the value, setting a variable to another one also copies the value, no matter the type. You must explicitly use a "ref" type if you want to avoid unnecessary copies. But acknowledging this, I made refs very convenient to work with. By this I mean assignment operators, arithmetic, & method calls all act on the referenced value, not the actual ref itself, making it seamless to use effectively. Of course you can still inspect properties of the ref using it's own type methods.
So yeah, that's how I went about the design of a memory safe language with simple & intuitive references. I am curious to see how your guys' *interpreted* languages went about solving references & memory safety, so do let me know of interesting alternative methods!
r/ProgrammingLanguages • u/The2ndSlimShady • 22d ago