DEV Community

Discussion on: If you could write a programming language how would it be?

Collapse
 
nektro profile image
Meghan (she/her)

I’ve thought about this a lot, and writing a compiler is actually one of the projects on my GitHub but I’ve realized recently that my dream language is actually just JavaScript with 2 changes.

1) Module only operation, nothing in global scope except primitives (String, Number, Array, Symbol, Object), every other API must me called via import
2) and the addition of a ‘use native’; directive that could be used to make JS fully compliable within certain rules. Ie: forced jshint comments on all functions to define parameter types, no setting a variable to a type other than its initial, and no dynamic property setting unless in constructor

Collapse
 
dwd profile image
Dave Cridland

You like those scoping rules? You think hoisting is in any way sane?

Collapse
 
nektro profile image
Meghan (she/her)

Scoping and Hoisting are two very different things. No I don't particularly hoisting but the way module mode keeps the global scope almost entirely empty as well as the import/export system is wonderful for both library developers and site developers alike.

Collapse
 
courier10pt profile image
Bob van Hoove

no setting a variable to a type other than its initial

+1 for type safe javascript w/o transpiling, I'd like that a lot

Collapse
 
eljayadobe profile image
Eljay-Adobe

... no setting a variable to a type other than its initial ...

At a previous company, they developed a language called TypeScript that transpiles into JavaScript (ES3 or ES5). (Sorry Bob van Hoove... yep, transpiles.)

One of its features was static type checking, which went a long way to eliminate a large category of bugs. The folks at Google liked it so much, that they used it for Angular 2.

I worked on a very large project that used TypeScript throughout, and it was pretty nice. (TypeScript also made available a lot of ES6 features, way before ES6 was ready for primetime. So that was very cool too, at that time.)

Now we have ES6 at our disposal, so at least one big feature that TypeScript still provides is the static type checking.

Maybe some future version of JavaScript (ECMA-262 and ISO/IEC 16262) will add that into the core language.

Collapse
 
nektro profile image
Meghan (she/her)

TypeScript is very cool and I especially like their idea of automatic constructor property assignment but unfortunately, TS isn't supported natively and must be transpiled :(

Collapse
 
orkon profile image
Alex Rudenko

You forgot 64bit integers and, perhaps, proper integers in general :-D

Collapse
 
nektro profile image
Meghan (she/her) • Edited

All numbers in JavaScript are automatically 64 bit floating-point numbers.
Source: ECMAScript 262 § The Number Type

Thread Thread
 
orkon profile image
Alex Rudenko

Do you say that a 64-bit float-point number is as good as a 64-bit integer? stackoverflow.com/questions/964362...

Thread Thread
 
nektro profile image
Meghan (she/her)

No, in a perfect world, as a part of the 'use native' directive I mentioned in my OP comment, you would be able to comment on variables to specify the number type

something along the lines of

/** @type i64 */ // i64 could be replaced with any of i8,i16,i32,i64,f8,f16,f32,f64
const num = 12;