Sign in to follow this  
Nathan2222_old

Just another thought (designing a fast but powerful language)

Recommended Posts

Nathan2222_old    395

I wanted to ask this in a previous thread but I thought it needed it's topic.
Would it be possible to make a compiled language as fast as c and c++, multi paradigm like c++, less complex than them both and can be used like in really complex situations like in making an OS/game engine/IDE etc.
Just wondering (may have mistakes above).

Thanks.

Share this post


Link to post
Share on other sites
jbadams    25674

Absolutely.

 

Whether or not any existing languages (such as the above-linked go and D) already meet most of those requirements is pretty subjective; we can obviously measure execution speed for code solving similar tasks, but what qualifies as "less complex" and what qualifies as "really complex situations" really depend on the skills and preferences of the programmer.

 

If you were thinking about starting such a project from scratch you should expect it to be very difficult, to take a lot of work, and to take quite some time to have anything workable; creating your own language (even if it's just a toy language) is however an excellent learning experience that's well worth undertaking at some point if you're interested in the low-level details of programming.

 

 

//EDIT: Please try to give your topics more meaningful titles; "Just another thought" tells a potential reader absolutely nothing about what they made find, so I've edited the title of this topic to be more descriptive.

Edited by jbadams
Added note re: topic titles.

Share this post


Link to post
Share on other sites
Nathan2222_old    395

//EDIT: Please try to give your topics more meaningful titles; "Just another thought" tells a potential reader absolutely nothing about what they made find, so I've edited the title of this topic to be more descriptive.


thanks for changing the title.

Share this post


Link to post
Share on other sites
Nathan2222_old    395

Absolutely.
 
Whether or not any existing languages (such as the above-linked go and D) already meet most of those requirements is pretty subjective; we can obviously measure execution speed for code solving similar tasks, but what qualifies as "less complex" and what qualifies as "really complex situations" really depend on the skills and preferences of the programmer.
 
If you were thinking about starting such a project from scratch you should expect it to be very difficult, to take a lot of work, and to take quite some time to have anything workable; creating your own language (even if it's just a toy language) is however an excellent learning experience that's well worth undertaking at some point if you're interested in the low-level details of programming.

i probably will undertake a project like this. I just feel like some things are more misunderstandable than they should be and there should be a better way.
Yersterday, i read an article saying that ruby/python programs involve 5x less lines than c and c++ programs. What does this mean?

Share this post


Link to post
Share on other sites
Nathan2222_old    395

Of course it would be possible but weather or not it is feasible or even productive is another matter.

by reducing the number of lines required to do something.
Which is why i asked about what 5x less means (i don't want to misunderstand it).
For instance, gta iv contained about 50,000 which included lines and comments. What if the need for the comments (not all) where reduced because you could tell what a piece of code does by taking a glance at it (even by some beginners) and some extra code and extra typing will not be needed thereby enabling you do things faster, increasing productivity.
You *could* reduce the line count by more than 10,000 (maybe).

Share this post


Link to post
Share on other sites
fir    460

Yersterday, i read an article saying that ruby/python programs involve 5x less lines than c and c++ programs. What does this mean?

 

 

dont think so, I was not using python to much but this would

meen (if the function of your code will stay the same and they

if they doing something nontrivial but real code - stay the same)

that every of such function will be compressed  5X of 4X

- i dont see it - it will be about the same [esp if you will remove the blank lines and move code like

 

void f()           {

  if(a==0)        {

      b++;            } }

 

(years ago i was using thic convention, this is not so bad imo)

 

what else python make to short sources compared to c ?

(maybe something but it would be imo more like 20% shorter not 5X 

Edited by fir

Share this post


Link to post
Share on other sites
Nathan2222_old    395

Sure, the infamous LOC metric. Read here for a more recent thread about.

yes i have been seeing the lines of code stuff lately.
I personally don't use comments but as for whitespaces and newlines, they're everywhere.
If code isn't clear and readable, then it's not useful. How hard can it be to press spacebar or enter ? You don't really notice it while pressing.
What i want is a language that is easy to understand, make readable programs with as fast as possible (with less or more lines depending on the user) and can be used in many scenarios. I'ld rather write 50 lines of code with white space and without comments than 50 without whitespace and with comments everywhere.
I saw a program that had a total of about 784,000 LOC and about 264,000 were spaces while about 128,000 were comments so that leaves about less than 390,000 executable LOC. It's the 390,000 i'm focused on (if i wrote that program, it'll probably way more spaces).

Share this post


Link to post
Share on other sites
Kirkkaf13    454
I would encourage you to have a look at some functional programming languages, SML, Haskell, Ocaml and Erlang.

I am by no means an expert in any of these languages but due to the high level design I find you can reduce your LOC dramatically.

I don't know how much these languages are suited for game programming or what tools are available but if you like a challenge and to expand your programming skills I highly recommend you delve into one.

Share this post


Link to post
Share on other sites
Nathan2222_old    395

I would encourage you to have a look at some functional programming languages, SML, Haskell, Ocaml and Erlang.
I am by no means an expert in any of these languages but due to the high level design I find you can reduce your LOC dramatically.
I don't know how much these languages are suited for game programming or what tools are available but if you like a challenge and to expand your programming skills I highly recommend you delve into one.

I've only heard of haskell.
I'm going to be learning assembly later on.

Share this post


Link to post
Share on other sites
LennyLen    5715

I am by no means an expert in any of these languages but due to the high level design I find you can reduce your LOC dramatically.

 

It depends on what you're doing.  If you're trying to perform mathematical expressions on a list of numbers, a functional language will most likely beat a procedural language hands down (in terms of LOC).  I'd hate to try to write an advanced application moreless verbosely though, as it's just not what they're designed for.

Edited by LennyLen

Share this post


Link to post
Share on other sites
Bacterius    13165

 

Yersterday, i read an article saying that ruby/python programs involve 5x less lines than c and c++ programs. What does this mean?

 

 

dont think so, I was not using python to much but this would

meen (if the function of your code will stay the same and they

if they doing something nontrivial but real code - stay the same)

that every of such function will be compressed  5X of 4X

- i dont see it - it will be about the same [esp if you will remove the blank lines and move code like

 

void f()           {

  if(a==0)        {

      b++;            } }

 

(years ago i was using thic convention, this is not so bad imo)

 

what else python make to short sources compared to c ?

(maybe something but it would be imo more like 20% shorter not 5X 

 

 

You do realize that when we say that Python code is shorter than e.g. C code we're not talking about removing the curly braces and a few comments, right? We're talking about the high-level structure of the code - Python is typically more expressive in less code, because it has a lot of stuff built-in (and cross-platform, for the most part), it's designed for short and concise syntax so that you don't have to implement all the stuff you need manually or use an external library (if even possible, like syntactic sugar).

 


(if the function of your code will stay the same and they
if they doing something nontrivial but real code - stay the same

 

That's the point - the code doesn't stay the same. It becomes shorter as a lot of the low-level complexity you have to deal with in C or C++ for instance is handled by the language and the runtime itself. Functions disappear because they become built-in, paragraphs of code become shorter because you don't need many lines to declare, initialize and populate a dictionary (key-value store) from a file, you can do it in one, you don't need to formally define complex object relations and dependencies since you have duck typing, variables are automatically freed, nontrivial command-line parsing is built-in and you don't have to go dig up a library on the internet and learn how to use it (more or less everyone uses argparse), big integers are built-in, you can even run Python code dynamically from existing code, etc, etc...

 

If you think Python is just C minus the curly braces then you clearly have never used it. It has its failings and doesn't work for everything (writing a large business application would probably get messy, and it has its warts) but when you use it - or Ruby, by the way, everything I said above almost certainly applies to Ruby even though I've never used it - for what it's meant for, the resulting code is surprisingly short and fluent.

Share this post


Link to post
Share on other sites
Nathan2222_old    395

dont think so, I was not using python to much but this would
meen (if the function of your code will stay the same and they
if they doing something nontrivial but real code - stay the same)
that every of such function will be compressed 5X of 4X
- i dont see it - it will be about the same [esp if you will remove the blank lines and move code like

void f() {
if(a==0) {
b++; } }

(years ago i was using thic convention, this is not so bad imo)

what else python make to short sources compared to c ?
(maybe something but it would be imo more like 20% shorter not 5X


You do realize that when we say that Python code is shorter than e.g. C code we're not talking about removing the curly braces and a few comments, right? We're talking about the high-level structure of the code - Python is typically more expressive in less code, because it has a lot of stuff built-in (and cross-platform, for the most part), it's designed for short and concise syntax so that you don't have to implement all the stuff you need manually or use an external library (if even possible, like syntactic sugar).

(if the function of your code will stay the same and they
if they doing something nontrivial but real code - stay the same


That's the point - the code doesn't stay the same. It becomes shorter as a lot of the low-level complexity you have to deal with in C or C++ for instance is handled by the language and the runtime itself. Functions disappear because they become built-in, paragraphs of code become shorter because you don't need many lines to declare, initialize and populate a dictionary . . .
that's what i mean. It's not the whitespace, it is just, shorter.
What do you mean by functions disappear etc.?

Share this post


Link to post
Share on other sites
LennyLen    5715

What do you mean by functions disappear etc.?

 

Imagine I had the following function in C++:



bool SomeElementIsTrue(std::vector<bool> vec) {

    for(std::vector<bool>::iterator it = vec.begin() ; it != vec.end(); ++it)
        if (*it == true)  return true;

    return false;

}

If I converted my program to Python, I can remove the entire function, and use the built-in 'any' function. 

Edited by LennyLen

Share this post


Link to post
Share on other sites
Nathan2222_old    395

What do you mean by functions disappear etc.?


Imagine I had the following function in C++:
bool SomeElementIsTrue(std::vector<bool> vec) {    for(std::vector<bool>::iterator it = vec.begin() ; it != vec.end(); ++it)        if (it == true)  return true;    return false;}
If I converted my program to Python, I can remove the entire function, and use the built-in 'any' function.
that is a lot of line difference :o.
Instead of that, you use:

any()
-6 lines for you and -7 for me.
That is exactly what i meant by reducing the amount of code needed to be typed to do something.

Share this post


Link to post
Share on other sites
alvaro    21246

What do you mean by functions disappear etc.?

 
Imagine I had the following function in C++:
bool SomeElementIsTrue(std::vector<bool> vec) {

    for(std::vector<bool>::iterator it = vec.begin() ; it != vec.end(); ++it)
        if (it == true)  return true;

    return false;

}
If I converted my program to Python, I can remove the entire function, and use the built-in 'any' function.


If I wrote that program in C++, I could remove the entire function and use the library `find' function, or just provide a one-line implementation of the function:

bool any(std::vector<bool> const &v) {
  return std::find(v.begin(), v.end(), true) != v.end();
}
Perhaps you didn't mean to compare an iterator and a boolean constant... smile.png

Share this post


Link to post
Share on other sites
Nathan2222_old    395

What do you mean by functions disappear etc.?

 Imagine I had the following function in C++:
bool SomeElementIsTrue(std::vector<bool> vec) {

    for(std::vector<bool>::iterator it = vec.begin() ; it != vec.end(); ++it)
        if (it == true)  return true;

    return false;

}
If I converted my program to Python, I can remove the entire function, and use the built-in 'any' function.
If I wrote that program in C++, I could remove the entire function and use the library `find' function, or just provide a one-line implementation of the function:
bool any(std::vector<bool> const &v) {
  return std::find(v.begin(), v.end(), true) != v.end();
}
Perhaps you didn't mean to compare an iterator and a boolean constant... :)

3 lines. Yes, the {} is counted.

Share this post


Link to post
Share on other sites
alvaro    21246
Also, if you insist on making things as short as possible, you'll end up with a programming language that looks like ASCII noise. Take a look at J for an example of a language that goes too far in that direction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this