Coding Shorthand

I’m wondering if Xojo will ever implement shorthand such as:

i++
i += 2

Is this really too big of a fundamental change that it will never be implemented?

Also I’m interested in any techniques anyone may know to shorten Xojo code. I don’t mean on a the level of overall application design. Just simple techniques applied to individual or small groups of code.

Why would you want to “shorten” code at the sacrifice of readability?
The compiler is smart enough that regardless of which syntax were implemented I’d bet the execuatble would be the exact same size.

[quote=166490:@Nicholas Henson]I’m wondering if Xojo will ever implement shorthand such as:

i++
i += 2

Is this really too big of a fundamental change that it will never be implemented?[/quote]

Discussed endlessly in the past here. It’s very unlikely to happen.

I can’t say that I try too hard to “shorten” my code. I try to keep it clean and clear and readable and sometimes that means you have to be a little more “wordy”. I find it better in the long run, though, instead of trying to interpret a few lines of code that have been reduced down until they aren’t as readable. Just my 2 cents.

My guess is probably not soon.

Techniques? Try Typinator / Keyboard Maestro / TextExpander. Set your shorthand with one of these and it will replace it for you. I do it quite often, for example I have one that expands dlog( to system.debugLog(|) and puts the cursor where the pole is. If you’re clever enough you could probably get them to do cool things.

Focus on writing clear maintainable code
Long term it saves you far more than typing ++ does

[quote=166496:@Dave S]Why would you want to “shorten” code at the sacrifice of readability?
The compiler is smart enough that regardless of which syntax were implemented I’d bet the execuatble would be the exact same size.[/quote]

[quote=166499:@Norman Palardy]Focus on writing clear maintainable code
Long term it saves you far more than typing ++ does[/quote]
I’d argue i++; is pretty easy to read and understand.

Goto Line 1 of my reply :stuck_out_tongue:

The other thing is it would 100% make your new code not possible to run in an old IDE
That seems to really bug people - go figure :slight_smile:

perhaps… then people will want

++i
–i
i+=2 (as mentioned above)
i-=2
and who knows what other types of operators, all to save a few keystrokes… PL/1 anybody?

[quote=166506:@Dave S]perhaps… then people will want

++i
–i
i+=2 (as mentioned above)
i-=2
and who knows what other types of operators, all to save a few keystrokes… PL/1 anybody?[/quote]
If you don’t like the shortcut don’t use it?

I think XOJO engineers have enough to focus on without changing the mathematical syntax

Plus i am talking about more than just mathematical syntax. I’m talking about modern coding short hand.

I also write out names in a more readable fashion, but what i’m talking about is more of a syntax modification in general. I love the way the ide is with coding compared to other environments. However, when it comes down to writing code there could be many updates made. (IE. Xojo Language 2.0 like every other language that evolves)

[quote=166501:@Norman Palardy]The other thing is it would 100% make your new code not possible to run in an old IDE
That seems to really bug people - go figure[/quote]

Sometimes you must give people what they need, not what they want. Take a leaf out of Steve’s book.

The Xojo language is always evolving. Check out the recent if() operator. http://www.xojonews.com/news/new-xojo-if-operator.html

Furthermore, the new Xojo framework can be, in handwavy kind of way, be thought of as Xojo Language 2.0.

This! is what i’m talking about. That is essentially what the “?:” Operator does in C#. I would love to be able to find more improvements like this. These kinds of implementations allow you to write less code that looks beautiful. It doesn’t look as elegant as the C# implementation, but a much needed improvement.

Okay then, maybe not what you’re looking for but you might like http://documentation.xojo.com/index.php/For_Each...Next

You are talking about c style syntax…

Xojo is not C and many use it precisely because it is not C like…

My brain fogs over when I look at C code. If Xojo became too C like I would stop using it! I know I am not alone in that sentiment.

  • karen

Here we go again. Is it not amazing that there are regularly people who apparently started with C trying to teach us how to love the so called “more elegant” notation of that family of languages.

A significant number of members of this forum have in the past or still use C for other project. Yet, they have chosen Xojo for very good reasons, and one of them is to be able to use a language made for human beings, close to plain English. Very successful professionals and amateurs alike use Xojo daily to produce excellent programs using the current notation they like.

Why insist on forcing on us an alien syntax coming from another language ? Norman is right. Before asking for decorations on the hammer, learn how not to bang onto your fingers first. Then if decidedly you do not like Xojo because it is not cryptic enough for your taste, go back to C and be happy, without ruining others life.

I chose Basic quite a while ago because I want to remain human. Computers should serve human beings, not the other way around.

Most amazingly, that sad phenomenon is not confined to this forum. Seems VB forums are victims of that kind of extremism as well
http://computer-programming-forum.com/6-vb.net/96f5ea61ebc9bb62-2.htm

Negative, i don’t want to change the syntax. Examples that Gavin Smith posted are what i was looking for with the new implementation of the If and for each.

Firstly i started writing in REALbasic when i was 16 after i discovered that i loved to code webpages so i wanted to try desktop apps. I have never switched languages since and have only dabbled. I love the way C# operates on a fundamental level not a syntax level. I would choose readability over cryptic any day.

These are decorations that could be added and utilized at will or not. It is not something that is forced there any many different ways to write the same statement. I only ask for better options rather than trying to work around missing features.

My only objective is finding shorter solutions to the same problem. For instance like Gavin’s example with the if statement:

if condition then
s = something
else
s = nothing
end if

Changes to:

s = if (condition,something,nothing)
^ This right here is beautiful and the kinds of implementations i’m talking about

i++ is a want

need is “a way to increment an integer” which i = i + 1 does already

I’m not saying it wont happen - we’ve discussed some - and there is a feedback feature request for them - its just a lot lower priority than say 64 bit, LLVM and the other items on our list (and yes its a fair amount of work to implement since you have to change the grammar, the parsers, compiler etc)

[quote=166506:@Dave S]perhaps… then people will want

++i
–i
i+=2 (as mentioned above)
i-=2
and who knows what other types of operators, all to save a few keystrokes… PL/1 anybody?[/quote]

pre and post operators make no sense in Xojo as they do NOT have the same semantics

In C its useful to have them - but in Xojo its completely pointless

+=, /= , *= etc may

but there are some that would likely never appear (yes we’ve dissed this internally)