Author Topic: My language  (Read 42933 times)

Vosvek

  • Guest
Re: My language
« Reply #15 on: May 30, 2018, 09:43:27 AM »
So sort of like a combination of Javascript and Assembly?

How would you reassign a variable within a struct? Also, how would you than +=, -=, <=, or >=? Should they really all be words? I mean, I want the ugliest language possibly, but it ought to be consistent. ;)

Code: [Select]
let WeekdayEnum
    Monday
    Tuesday
    Wednesday
    Thursday
    Friday
    Saturday
    Sunday

let FooBarStruct
n       1
str     "Apple"
real    3.4r
b       true

let structFunc(FooBarStruct a)
increment   a.n
add         a.str   ", Apple"
subtract    a.real  1.2
let         a.b     false

let reflectionFunc(var o)
if o has int n
increment n
if o has string str
add str ", Apple"
if o has real r
subtract r 1.2
if o has bool b
let b false

let a FooBarStruct
structFunc(a)
reflectionFunc(a)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #16 on: June 17, 2019, 10:07:46 AM »
I've been reading some pages from 'Language Implementation Patterns' by Terence Parr. This is supposed to be a light weight book, but it's still pretty hard core I would say. I don't really understand a lot, but the book is I guess about parsing languages and it's talking about stuff like complexity of C++. If you think about it C++ (also the C part of it) is quite complex and sometimes ambiguous. You have stuff like pointer arithmetics and const keyword which can be placed almost anywhere. Thinking about that it would be interesting to create a simple language with restricted ways to do things, even if it means you have to write more code.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: My language
« Reply #17 on: June 18, 2019, 06:26:30 AM »
Guess what. Such a language has already been created. It's called Java. But I don't see anything interesting in it :P. If you like being restricted, write in Java. If language's complexity motivates you rather than intimidating you, write in C++. If you want to waste your lifetime creating yet another useless language that will save the world...
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #18 on: June 18, 2019, 06:53:01 AM »
Such a language has already been created. It's called Java. But I don't see anything interesting in it :P.

I don't think Java is a simple language. I think it removed pointers? I'm actually not that familiar with Java. But I know some languages began from a "need" to fix C++ problems (like pointers) which I think is a silly way to think about it. Even C++ wants to fix itself by new versions.

Quote
If you want to waste your lifetime creating yet another useless language that will save the world...

I've already wasted my life so it doesn't matter that much. Besides nothing we do is that important if we get philosophical. Creating a language is something I see an interesting idea, because working with C++ and knowing a bunch of other languages I have a strange feeling that things could be done in some other way.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: My language
« Reply #19 on: June 19, 2019, 06:46:19 AM »
I don't think Java is a simple language. I think it removed pointers?

It's not simple, it's simpler than C++ (in terms of syntax). They haven't removed pointers, only wrapped them in "references", which makes them harder to control. But let's look at C++. In addition to "normal" pointers it also has function pointers, class method pointers and object data member pointers (but it does not have object method pointers, which adds to the confusion). Additionally, since C++11 we have 3 new types of so called smart pointers and now-deprecated auto_ptr. That's already 8 different types of pointers. There's also something called reference, which is nothing more than a different syntax for a pointer. And, since C++, r-value references. This way we end up with 10 pointer types, more or less incompatible with each other. C++ allows to create levels of indirection with pointers (but luckily not with references!), so that we can also have pointers to pointers or even pointers to pointers to pointers to pointers to pointers. And I'm not going to talk about all possible combinations of "const", "volatile" or "const volatile", placed before or after the '*' (although this is pure fun). Did I mention iterators? Of course, iterator is yet another concept of pointers, with totally different syntax and usage... Enough?

I think Java now seems pretty straightforward and friendly, but I sometimes wonder how novices must feel when they encounter a "null pointer exception" time after time, with all those people telling them that Java has no pointers :).
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #20 on: June 19, 2019, 12:18:02 PM »
I think we can agree that C++ is a complex language. That was kind of the point, maybe languages could be simpler and force the programmer to follow more strict rules, in a good way. In fact I don't quite understand why C++ is so complex, what was the reason for that? Maybe backwards compatibility with C, but then why C was/is that complex? Was it because that's how they were thinking about languages back in 1960's and 70's when most of them were invented, who knows.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #21 on: June 27, 2019, 12:52:03 PM »
Another way to make languages easier to use would be a higher level thingy created on top of an existing language. Some languages compile to C (or whatever), but I was thinking more like a "construction kit" for some language. For example it would be really nice to have a graphical design tool for planning class hierarchy in C++. It would make the first phase of modular (as in what file contains certain classes) design and also class hierarchy design much easier. I guess those kind of tools exist, but not in freeware/open source.

Vosvek

  • Guest
Re: My language
« Reply #22 on: June 28, 2019, 03:36:53 AM »
I think we can agree that C++ is a complex language. That was kind of the point, maybe languages could be simpler and force the programmer to follow more strict rules, in a good way. In fact I don't quite understand why C++ is so complex, what was the reason for that? Maybe backwards compatibility with C, but then why C was/is that complex? Was it because that's how they were thinking about languages back in 1960's and 70's when most of them were invented, who knows.
C really isn't as complicated as people say, you just need to be a little patient with it and think through what you're actually trying to achieve. Yes, you don't have namespaces or structs with associated functions and private variables (object classes), there is no built-in boolean type (and stdbool sometimes conflicts with old libraries), and strings/char */char[] are awkward, but it's not that difficult to work around these limitations, or understand why the languages works the way it does. Not to mention, these very limitations can give you a different perspective on how you design your code, and push you towards alternative approaches like object pools and relational databases, both of which come with the benefit of knowing exactly where your memory lives, where leaks could occur, and how everything can be coupled, decoupled, or associated. It's especially simple by comparison to C++, for better and worse. :)

C backwards compatibility for C++ definitely adds to C++'s complexity. But it doesn't help that the C++ community is divided between OO patterns + 'RAII, not raw', and 'Stop abusing OO'. On one hand, there's a crowd that effectively wants Java/C# but with RAII pointers and manual/no garbage collection (C++ has been on this path for a while, D was almost there, but backed out, and Rust seems to be heading this direction), and on the other hand, there's a crowd that wants C, but cleaner and with some of the tools from C++ (which is the current mob voicing their concerns over C++'s future, and resulting in languages like Jai, and Unity's Burst Compiler). As a result, C++ is stuck in the middle, trying to cater to both, satisfying neither, and has become a kitchen sink full of dirty dishes. You'll find whatever you need in there, but you'll have to sift through the slime and clean it first.

Another way to make languages easier to use would be a higher level thingy created on top of an existing language. Some languages compile to C (or whatever), but I was thinking more like a "construction kit" for some language. For example it would be really nice to have a graphical design tool for planning class hierarchy in C++. It would make the first phase of modular (as in what file contains certain classes) design and also class hierarchy design much easier. I guess those kind of tools exist, but not in freeware/open source.

Isn't that what parser generators (i.e. YACC, ANTLR, Yeti, etc.) and compiler toolchains (i.e. LLVM, GCC, etc.) are for? Or are you talking about visual programming languages, or visual programming languages specifically designed for building scripting languages?

As far as I'm aware, Visual Studio does have a graphical C++ class designer. I know they definitely exist for C# and Java (and in all honesty, they're quite finnicky and not as useful as just hammering in code yourself, which is a shame).

As an added, you've probably already seen it, but Bob Nystrom is currently working on a book about creating scripting languages. It might be worth checking out if you haven't already: https://craftinginterpreters.com/

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #23 on: June 28, 2019, 07:42:10 AM »
I'm clearly not thinking about C++ the same way. OOP is mostly a structural thing that helps in organizing the code. It's not a complex thing at all compared to everything else in C/C++.

The "class construction kit" would create the files and empty classes (or with some variables if defined) for the whole project. Then you would have the class hierarchy ready, which I think is sometimes difficult to understand and create when you just start to write the source code without plans.

Vosvek

  • Guest
Re: My language
« Reply #24 on: June 29, 2019, 07:28:05 AM »
I'm clearly not thinking about C++ the same way. OOP is mostly a structural thing that helps in organizing the code. It's not a complex thing at all compared to everything else in C/C++.

The "class construction kit" would create the files and empty classes (or with some variables if defined) for the whole project. Then you would have the class hierarchy ready, which I think is sometimes difficult to understand and create when you just start to write the source code without plans.

OO is not complex, but the strive for "greater" OO support directly contributes to the messier, complex parts of C++.

That still sounds like a class diagram/designer, which Visual Studio has had since 2005.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #25 on: June 29, 2019, 07:51:52 AM »
That still sounds like a class diagram/designer, which Visual Studio has had since 2005.

Well, at least you have to install it in VS2019 which I did, after all these years not knowing about it.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #26 on: July 13, 2019, 04:30:44 PM »
"Language Implementation Patterns" by Terence Parr was difficult to understand and for the most part I didn't, but it has started me thinking about simpler version of languages. For example when you think about class, struct and namespace in C++ they are more or less the same thing and there should be only 'class' keyword for all purposes. Enums are bad in C++, because they are basically ints and add lots of confusion, so they should also be removed. It's interesting to think about a version of C++ with actual OOP paradigm and simpler structure.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: My language
« Reply #27 on: July 15, 2019, 05:55:38 AM »
For example when you think about class, struct and namespace in C++ they are more or less the same thing and there should be only 'class' keyword for all purposes.

Once again, that's Java. And Java is a great example of how simplifying a language in one place leads directly to making it much harder in another. What we have now in C++ just reflects the complex nature of programming. Java tries to hide the complexity by using sophisticated abstractions, but this of course does not remove the complexity. But as long as you are not a startup owner thinking about conquering the world with 10000 high school interns, the existence of 'class' an 'struct' in C++ should not be a big obstacle for you.
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #28 on: July 15, 2019, 10:51:41 AM »
Once again, that's Java. And Java is a great example of how simplifying a language in one place leads directly to making it much harder in another.

I always thought Java more or less as complex as C++. Maybe it has removed some things that C++ has, but there seems to be plenty of keywords in java. I think most modern languages are way too complex and large. Like python, swift, C# etc. Not only the language, but libraries on top of that.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: My language
« Reply #29 on: May 11, 2020, 08:28:30 AM »
This is the way switch-case would work.

Code: [Select]
switch i
case 0
print "case 0"
case 1
if x is 5
break
print "case 1"
cases 2 ... 8
//range version
default
//default case

Each case would have automatic break (even empty ones, or possible empty cases would be illegal), but you could group them with a range.