What about Inc, Dec?

Post your Gambas programming questions here.
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

What about Inc, Dec?

Post by Cedron »

First time poster here.

I've been playing around with Gambas quite a lot for the last few weeks. One of the improvements over any flavor of BASIC is the inclusion of the combined operation/assignments:

"x += 1" is so much nicer than having to "x = x + 1"

Particularly when you use long descriptive variables like I like to do. Gambas also has "Inc x" for when the value is one. They work the same, not sure if one is more "efficient" than the other at run time, but I suspect not.

So my question to you all, especially the more experienced programmers, what is your preference?

x += 1 or Inc x

Or perhaps

myQuestionCount += 1 or Inc myQuestionCount

Thankfully, "x++" is not also an option.

When somebody asks you what Gambas is, you can answer "Inc VB", get it?

Marching forth today.

Ced
.... and carry a big stick!
User avatar
Quincunxian
Posts: 173
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: What about Inc, Dec?

Post by Quincunxian »

Hi Cedron,
Welcome to the Forum.

I always use +=1 / -=1 although the -=1 always makes me feel irritated as it doesn't feel right.
Think its just the fact that the minus sign is easier to miss if you are quickly reading over code.

Few tips to help you on your way.

In code view, place the cursor over a Gambas language function such as Inc and press F2.
This will open the on line help/description for that function.

In GUI (form) view, if you right click any of the component icons in the display on the bottom right hand side of the screen, it will also open the on line help for that component.
Cheers - Quin.
I code therefore I am
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: What about Inc, Dec?

Post by Cedron »

Hi Quin,
Thank you for your kind words and welcoming attitude.

I'm actually a very long time programmer. Let me give you a clue, my first language was VSBASIC on an IBM 360, on a genuine Teletype terminal. If you can type fast on that, you can type fast on anything. Program storage was done with a punched tape on the side.

I learned FORTRAN almost simultaneously. Of course, that was with punched cards, a card reader, and a line printer for the output. I should also mention we had to walk to school five miles each day, uphill both ways, in a blinding snowstorm, and we like it that way. ;-)

I've done a lot of coding on a lot of different platforms at a lot of different levels. This part is true. Including assembly on PCs and some on mainframes.

So, just laying some foundation. I'm working on a coding style document that I hope to post here in the near future to share the practices that I have found very useful for both creating code and making it easy to maintain.

Along the way, VB3 through VB6 were always my favorite platforms to rapidly develop GUI applications. I am a veteran of the "Language Wars" of the nineties, so if you want to discuss the relative merits of various languages, I'm game.

One thing I can say with certainty, the anti-BASIC sentiment that seems to prevail with programmers who claim to be "real programmers" and don't mess with toy languages, is totally unfounded. They can usually be shut up with a discussion about stack frames and optimal register usage.

I am liking Gambas a whole lot. I wish I would have found it earlier. I have a whole backlog of really cool programs I want to develop, as well as doing what I can to contribute to the Gambas project.

Getting back to the question in the subject line. I'm kind of indifferent, but lean towards the "x += 1" rather than the Inc. BTW, inc and dec are actually assembly language commands as well.

I tend to use the "+=1" version is C styled code because I find the ++ (and most of C) really ugly, and I like good looking code.

It's easy to make in Gambas. It is better than VB6 hands down. Well designed and a very comprehensive IDE. Plus, it's on Linux.

I was just beginning to like Python (which I consider a dialect of BASIC), but I don't care for variants. I didn't like them when they were introduced, and I don't like them now, and that is what Python is all about. Strong typing helps prevent a lot of errors that sloppy programming with variants introduces.

Enough for now, thanks for the welcome.

Ced

myPostCount += 1
.... and carry a big stick!
User avatar
Quincunxian
Posts: 173
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: What about Inc, Dec?

Post by Quincunxian »

Sounds like we are around the same vintage.
Taught myself to code in GWBasic on an old 8088 chip set PC with 16K of free RAM
I also did some time on an IBM system 36 using RPG3 which was a bit different.
Mostly done VB.net for work but now retired so much prefer to use Gambas.

Think I saw a bench mark somewhere that had Gambas running faster than Python for quite a few functions so it certainly has the grunt to be a 'commercial language'

The strong typing is really good to teach new coders about good practice.

I feel that biggest problem with Gambas has been the lack of on line help but has got a lot better over the last few years. When I first started with Gambas 2, there was not much about apart from a decent downloadable pdf by a guy called John Rittinghouse who wrote a Beginners Guide to Gambas.
Last (free) version I had was around 2005 and most of it is still relevant although there have been some significant changes around use of loop variables. They now must be local that the proc/funct that they are used in. String array declaration can be a bit different depending on global or local.
There is a revised edition for Gambas 3 I found on Amazon but the price is ridiculous at $300+ for what it is.

The one component I really miss is a checked list box - I've made one as a class but can't get my head around the instructions for creating a formal Gambas component ( anyone else reading this who does - please give me a shout as It would be a useful addition to the set.
Cheers - Quin.
I code therefore I am
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: What about Inc, Dec?

Post by Cedron »

Old farts club. :-) I should have looked at your profile before I posted my previous reply.

Yes, I have a copy of that too. Out of date, and not useful.

I've been deep diving into Gambas.h, and studying the architecture. I'm getting quite knowledgeable.

There are two flavors of components. Gambas and C. I've gotten the former to work, but not the latter. Apparently you have to fork the Gitlab source, develop it, and submit a merge. At my level of expertise now, that is too much. There is still plenty of learning I can do without taking that step. I've been excerpting the .h file to see if I can at least get them to compile, but the set up is quite intricate and it is not encourage. They are quite busy on the bleeding edge so I don't really want to bother the experts with newbie questions.
I have a wrapper for libusb as a Stream class pretty well started, but I hav run into udev troubles opening the devices. The .rules solutions I found online don't seem to work, so rather than get flustered or bother anyone I am moving onto something else.

I'm working on a real diamond right now. Something you will want badly. That is all I want to say for now.

I assume you are able to compile shared library. If you would like to check out the video game I wrote as a Gambas learning exercise, send me an email and i will send you the source. I am not posting it to the farm until there is a GamePad component in the official distribution. I've written one, but it is flawed. Hoping someone will pick it up and finish it before I get back to it, but like I said, they are busy on leading edge.

I am extremely impressed by this whole project. My other big project is to write a generator for producing wrapper functions so the GBgsl (Gnu Scientific Library) component spans the entire functionality of that library. That is not trivial either.

So, I'm back up to user level, getting to know the product better. I am pleased at every turn. So many more features and nice little touches compared to VB.

I've also seen timing benchmarks that show Gambas faster than Python, but that isn't that important. If you want speed write a C based .so. The ease of calling it from Gambas code really impressed me. I got my little test working the first time, which as you know is usually rare.
.... and carry a big stick!
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: What about Inc, Dec?

Post by stevedee »

Cedron wrote: Monday 4th March 2019 7:50pm ...So my question to you all, especially the more experienced programmers, what is your preference?

x += 1 or Inc x...
Yes, welcome to what is officially the friendliest forum on the internet. This is possibly due to there only being 67 members (a.t.o.w.).

I too am very old, and my first computer was probably made from the rib cage of some kind of dinosaur ...floating point arithmatic was a bit of a bugger.

Inc/Dec are always my first choice for incrementing or decrementing integers (I can't think why), followed by x = x + 1 (but I wouldn't get into a stand-up fight over it).

I mostly use the other thing to append text, as in:-
 Me.Text &= "...now what's it bloody doing?" 
...or do anything except increment or decrement some value.

Have fun with Gambas, but don't take this programming malarkey too seriously. The real world is floating around outside.
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: What about Inc, Dec?

Post by Cedron »

Yes, welcome to what is officially the friendliest forum on the internet.
Okay, I gotta say: Where is it written? And who enforces it?

In the early days, when the first task of the morning was to clean the pterodactyl poop off the porch, I wrote my own little assembler. My thought was if I could make the machine codes represented by BASIC like syntax instead of Assembler syntax, it would look nice and more people could do it.

Code: Select all

    mov cx, ax
    cmp cx, bx
    ja T
       mov cx, bx
T:  mov dx, ax
    add dx, bx
    sub dx, cx
vs

Code: Select all

    cx = ax
    compare cx to bx
    if above goto T
       cx = bx
T:  dx =  ax
    dx =+ bx
    dx =- cx
Even then, I didn't like having to type out the redundant x = x + 1.

I was able to produce .com files, then it came to writing .obj files. Where is the structure documented? Only one place that I knew about (pre-internet), in a book call "The MS-DOS Encyclopedia". So I bought it, even though I was a poor struggling college student (no exaggeration there) and it was expensive. Talk about over-engineered complexity, yuck, it didn't go farther. However, the book is still on my bookshelf.

Later, I learned C. Wondered about why += instead of =+ which was more natural to me. Answer: They parsed different and didn't rely on spacing.

Does x=-y mean x = x - y or x = -y? Spacing counts, x =- y vs x = -y and it is clear. So, -= is actually a good solution. Yeah, I find it difficult to be complimentary about C.

Back in the aforementioned language war days, this was the only club that the C guys could beat the BASIC guys with. Of course, we could beat them right back with inherent string handling, and wait for it.....

Let's all praise the mighty GOSUB statement. I can pull a chunk of code out of an overburdened control structure, move it below, put a label on it, leave a gosub behind and leave much more comprehensible code behind. The only way you can do that in C is with gotos. Well, we all know what a goto meant to a C guy debating a BASIC guy, so they weren't going to advocate that. Nor is it as good of a solution.
Have fun with Gambas, but don't take this programming malarkey too seriously. The real world is floating around outside.
Single precision or double precision? Float is unclear. One of the very few poor design decisions I've seen Benoit make.

Lately, (meaning the last few years), I haven't really been programming a lot. Programming to get things done, rather than just to produce something cool. For example, here is a code piece of mine in Python:

https://dsp.stackexchange.com/questions ... 4879#54879

From now on, my code samples are going to be in Gambas, with a little blurb explaining that, and where to go to find out more. I'll try to slip in a mention or two about this forum if you'd like.

Anyway, I'm enjoying programming again, so I am going to return to the tetrahedral carbon structure in hopes of making it presentable. Where is that coal pile at again?

Regards to all you friendly people,

Ced
User avatar
Got2BeFree
Posts: 91
Joined: Saturday 26th November 2016 2:52am
Location: Lost

Re: What about Inc, Dec?

Post by Got2BeFree »

stevedee wrote: Tuesday 5th March 2019 7:04am Yes, welcome to what is officially the friendliest forum on the internet.
The blame for it being the friendliest forum I put squarely on the other members here. It's their fault! :D

stevedee wrote: Tuesday 5th March 2019 7:04amThis is possibly due to there only being 67 members (a.t.o.w.).
I accept the blame for that. :cry: This forum was thrown together quite quickly by cogier and Jornmo to fill a needed void after I abruptly shut down GambasForum due to personal issues. Unfortunately, many of the members from GambasForum didn't make the move to Gambas One.
sholzy

I'm wondering around lost in the past, not knowing where the present is.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: What about Inc, Dec?

Post by stevedee »

Got2BeFree wrote: Thursday 7th March 2019 5:59am ...I accept the blame for that...
No blame, no shame...we are just glad to have you back mate!

...and yes, the boys have done a good job putting this site together.
Its not about numbers. Over time, people join a forum, then drop out but never leave...I feel a song coming on...

"...you can check-out anytime you like, but you can never leave..." {the Brexit song by Jean-Claude Juncker}
User avatar
cogier
Site Admin
Posts: 1125
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: What about Inc, Dec?

Post by cogier »

"...you can check-out anytime you like, but you can never leave..." {the Brexit song by Jean-Claude Juncker}
Very good Steve. You had me laughing this morning with this.

Inc myPostCount
Post Reply