Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Can you (would you) += in MMBasic
Page 2 of 4 | |||||
Author | Message | ||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
Also time to read up about SUBs and FUNCTIONS. To expand on the earlier example to allow for increments other than one. Once-upon-a-time we only had single precision floating point numbers and life was easy. We now have integers as well so my example is not very good. There really needs to be two SUBs. INCf and INCi. The more advanced MMBasic gets, the more disciplined the programmers have to be. A good thing but not as much fun. I've already had one migraine today so that's enough for me for now. Jim VK7JH MMedit MMBasic Help |
||||
karjo238 Regular Member Joined: 12/10/2018 Location: New ZealandPosts: 54 |
Jim - That works for me! As I said, it's very much a personal thing, but that code will do exactly what I need and will be used forthwith. Please, go hither and relieve your migrane with my sincerest thanks. It's wonderful to reach out and receive assistance when it is asked for. Joseph |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
Yep, that's another result of the trends I was outlining above. COBOL just wouldn't let you write undisciplined code. Geoff's OPTION EXPLICIT enforces pre-dimensioning variables. dBase let you write all kinds of junk into your code without complaining. There are a few things I wish Geoff would change about MMBasic but it would require branching from the "normal" BASIC. I think that arguments passed to procedures (subs or functions) should always be delimited, but not with "()" pairs, rather with "[]" pairs. This would avoid the possibility of confusing arrays with procedures. In a for next construction it is optional to specify the variable after the next for i=1 to 10:for j=1 to 10:'do something:next j,i thus tying a next to a specific for. I think that it should be optional (and recommended) to include the name of a procedure after the end procedure statement. sub XYZ 'do something end sub XYZ thus tying a procedure close to a specific opening statement. Minor points but ........... Paul in NY |
||||
flip Senior Member Joined: 18/07/2016 Location: AustraliaPosts: 114 |
...also for consistency (and maybe if it gives faster execution) do it for string variables... a$ += " append a bit" But totally up to Geoff. Just my 2c, but If they give no performance benefit, I prefer putting these sort of personal preferences into a pre-processor, it is simple to do, and pre-processors have many other side benefits for end-users, and can prevent fragmentation of the core design. Again, just my 2c...I'm sure many valid views can be expressed on it... Regards Phil |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Idiosyncratic, for sure, based on my programming experience. And it would break a lot of perfectly good code. sub XYZ 'do something end sub XYZ thus tying a procedure close to a specific opening statement. If optional, it could without breaking things identify some (I think rare) conditions where one subroutine was unintentionally inserted within another, but if intended to be informational and not syntax-constricting, "END SUB ' XYZ" would work (and I frequently use that with long SUBs). PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
Idiosyncratic, for sure, based on my programming experience. And it would break a lot of perfectly good code. sub XYZ 'do something end sub XYZ thus tying a procedure close to a specific opening statement. If optional, it could without breaking things identify some (I think rare) conditions where one subroutine was unintentionally inserted within another, but if intended to be informational and not syntax-constricting, "END SUB ' XYZ" would work (and I frequently use that with long SUBs). sub XYZ 'this sub does something But, if I forget to stick in the first <'> after the end sub it breaks MMBasic. 'do something end sub 'XYS 'this sub does something Paul in NY |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
>breaks MMBasic Seems extreme to say that the programmer's omission of a single quote ("'") "breaks" mmbasic, when what it actually does is produce a syntax error, just as most comments would if the comment indicator symbol were omitted. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
karjo238 Regular Member Joined: 12/10/2018 Location: New ZealandPosts: 54 |
I'll ask this question here, as this is related to some of the answers already posted in this thread. I have created the simple code: DIM A(6) = (0,1,2,3,4,5,6) print a(3) This returns 0, when I would have thought it would have returned 2. I'm doing something badly wrong, I'm sure, but what? Answers on a ticking timebomb please... Joseph. |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
I was just playing with the latest beta version. Tested it and it printed 3 for me. Bill Edit: list Dim A(6) = (0,1,2,3,4,5,6) Print a(3) > run 3 > Keep safe. Live long and prosper. |
||||
karjo238 Regular Member Joined: 12/10/2018 Location: New ZealandPosts: 54 |
After I posted, I wondered if I had an older version or some such. My MMBasic is 4.0402, and the MMBasic manual version 4.5 does not mention this capability, but the DOS MMBasic (version 5.05) manual mentions this feature. Soooooo, I'll have to do some rejigging to update my Maximite because it's running off the USB as a power source, and I really should get a 9V power supply. It's all good, as I have been meaning to do this anyways. This just gives me an extra reason to get about doing it. Many thanks, Joseph. |
||||
spock57 Newbie Joined: 24/09/2017 Location: United KingdomPosts: 4 |
I'm new to the forum in as much I'm a regular reader but usually keep my gob shut! Some forty years ago when I was young and all the extremities moved as they should, I remember a mantra that went something like the "operating system should be transparent to the user" ,oh what a great Idea! In the last ten years or so I was nearly guilty of murder every time some IT bod would say the system expects me to do it this way, it's the technophobes worst nightmare the user serves the system, it's not very humane what did we gain? So whats this got to do with MM basic, well the attraction of basic back then and now was the relative ease of use, improvement is all well and good but when you start with a Ford escort for the shopping and improve it until It's a Jaguar Ok it's faster but will it take a kiddy seat? The way I see it if you don't need massive performance and just want to get something done no fuss use Basic ,if you are cleaver enough to shoot holes in the validity of using basic you are probably better off using C or some other language that is quick efficient and probably a nightmare to use unless you have the right sort of aptitude. Please please keep it simple I'm a lousy programmer Basic is nice and text based I have great difficulty in spotting the difference between <> {[ }] () and these symbols to are name but a few I will never live long enough to understand C, tiny basic is probably good enough for me the MM basic reminds me of my old Tandy model 1 (sigh). That's me done I will not rant on any more. Ps apologies in advance if I'v posted incorrectly! |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Well..... :) Even in C, C#, C++, Java and javascript I mostly use a = a + 1 It is just five characters (without whitespace) and a += 1 is four characters. Just saving 1 character is not worth it. and for my personal taste the first style is preferred. However there are situations where there can be 'expensive' evaluations like MyArray[J+1][K+1] = MyArray[J+1][K+1] + 1 The interpreter then has to evaluate the same expression twice, resulting in about twice as long execution time. Often those more expensive expressions are used in loops, therefore using the += is more efficient. If you want to squeeze out the most performance then that can be a reason to use it. With compiled languages it does not matter as it will be optimized anyway. Microblocks. Build with logic. |
||||
memberx Newbie Joined: 20/04/2012 Location: AustraliaPosts: 24 |
Amazing, old dinasaurs, either because of incompetence, laziness , or whatever, want to stop progress. Computers, electronics, programming is evolving technology and is not for everyone. If it's too hard go and find something else. |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Judgmental much? What's amazing is that you can lower yourself to follow a basic forum. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2817 |
Been monitoring this thread with keen interest, and until now I have held back from posting as I wanted to see what other people's feedback was. Having built, used, supplied, and demonstrated literally thousands of Micromites and Maximites over the last few years, my belief is rather straightforward: MMBASIC code should 'look and feel' obvious to a non-systems person I have demonstrated MMBASIC to a LOT of people, of various ages and skill-abilities. The amazing thing observed on EVERY occasion is that people 'get it' because of how easy it is to understand. And this is exactly what BASIC was designed to be. Maths expressions learnt at an early age are easy to identify with within BASIC code and hence are totally meaningful. Obviously new features require new commands, but the overall context should still be simple and obvious. 'Progress' is relevant and Geoff and Peter (and a few others here) have implemented things in a totally meaningful way; apart from, (dare I say it) << and >>. These << and >> expressions still require me to stop and think. A newcomer has no-chance - I have asked people in demonstrations and not one 'newbie' has been able to answer correctly. If you are a systems person then they sure will mean something obvious (and so probably will C programming!). By the way, I use multiply and divide to do my 'bit shifting'! My opinion regarding: a += 1 is that it is not obvious to a 'newbie' in any way; and anything not obvious does not really belong in (MM)BASIC. So progress is good, I have no 'laziness' in learning new things, but PLEASE let us preserve the simplicity, i.e. the look & feel, of MMBASIC code in the years to come. For everything Micromite visit micromite.org Direct Email: whitewizzard@micromite.o |
||||
Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 830 |
The dinosaurs lived about 190 million years, man 300000 and is already about to extinguish himself - what is better? I'd rather be a dinosaur with an interesting hobby!!!! What did Spock say: Scotty, beam me up, there is no intelligent life on this planet! I love BASIC because of its simplicity! For me it is also not a real advantage if I have to close my pants with a glowing pair of pliers! +1 WhiteWizzard: MMBASIC code should 'look and feel' obvious to a non-systems person |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
Hmmpff. Darn right I'm a dinosaur! I still think that Grace Hopper was right, a program language should enforce divisions .... namely Identification, Environment, Data, and Procedures. Every major bank in the world is running on programs which were coded 50 or more years ago and are still functioning perfectly, thanks mostly to the partitioning enforced by the COBOL divisions and the modularity of the procedures! Progress for progress' sake is not progress ... it quickly becomes anarchy. Bill Gate's dream of non-modular programming is a case in point. He advocates divorcing a patterned sequence of events from programming. This results in a word processor where you can first mail a letter, then insert the letter in an envelope, then address the envelope, then print the letter, then .... well, you get the idea. Real world tasks dictate the sequence of events that must occur before a task is completed. Real world programming enforces a similar sequence of events! And .... I even like Reverse Polish Notation! Paul in NY |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Let's not forget that the Micromite (and Maximite to a large extent) are intended to be used as microcontrollers. There are many commands that have been implemented for this purpose: IR, PIN() PORT, PWM and so on. For that reason I like the '>>' and '<<' expressions. When you are dealing with binary numbers '>>' and '<<' to shift bits are more intuitive to the programmer than '/' and '*'. I Expect they are faster as well. Have a look into some the Maximite games programs. In many of them there is extensive use of the: a = a + 1 type of construct. If: INC a [,Number] could be implemented along with it's mate, DEC, for use with INTEGERs and if they operated faster than the 'a = a + 1' method, then I believe they would be a useful addition to the language. Bill Keep safe. Live long and prosper. |
||||
Bill7300 Senior Member Joined: 05/08/2014 Location: AustraliaPosts: 158 |
Absolutely nothing wrong with being a dinosaur - the trick is rather to avoid becoming a fossil! Bill |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2075 |
Sadly not: a=57 timer=0 for n=1 to 10000 a=a<<1 next ? timer a=57 timer=0 for n=1 to 10000 a=a*2 next ? timer > RUN 1081 967 > bummer! |
||||
Page 2 of 4 |
Print this page |