new eScript operator

Archive of the older Feature Request Forum Posts
Locked
phao
Grandmaster Poster
Posts: 129
Joined: Fri Aug 31, 2007 2:25 pm

new eScript operator

Post by phao »

well, i dont know if i'm in the right section, because this would be an Ecompile feature suggestion, if there is a better place for this post, let me know.

I think it'd be nice if I could use ? : operator in eScript, i think this operator will save a lot of lines of code and if/else lines.

It isnt hard write if/else lines, but when you do this everytime, you think that it could be good to have something to 'compress it'.

For who doesnt know ? : operator, i'll explain:

Code: Select all

return (1 == 2 ? "hi, 1 is equal to 2" : "no no no");
it'll see if 1 is equal to 2 if yes it'll return the thing after the ?, if no it'll return the thing after :

so something like this

Code: Select all

user := there is a user flag? 1: 0;
instead of doing

Code: Select all

if there is a user flag
  user equal to 1
else
  user equal to 0 
endif
yeah, i know a lot of people will say it's useless, but save a lot of boring lines of code.

this feature is used in languages like C, C++, JavaScript, and others, and it comes from functional programming, if you have programmed in Scheme or Common Lisp you've seen something like (if (pred) (true action) (false action)) and, IMO, it's a lot practical, for me eScript could be 100% functional programming :) heheheh (just kidding)
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

I can understand why this might be a nice addition to eScript. It does seem to be a time-saver for entering code.

I have a couple objections to implementing this. One is readability of code. Currently if statements are easily found and recognized. Using symbols rather than pseudo-linguistic statements reduces the readability factor.

My second objection is that the more you add cryptic constructs to a language the harder it is to learn, especially for people who have little or no previous programming experience. Many of us were blessed with some prior knowledge of programming when we came to POL but a lot were not and I think this might make it a little harder for those folks to learn eScript.

Ofcourse I am assuming that the POL developers want eScript to be easily learned by people.
Locked