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 1 of 4 | |||||
Author | Message | ||||
karjo238 Regular Member Joined: 12/10/2018 Location: New ZealandPosts: 54 |
I have been happily beavering away writing code in MMbasic, and have been *loving* it. It really is a blast going back to basic (pun intended) and have a ball whilst doing it. One thing that was never in Basic of any kind that is present in most modern languages is += i.e. rather than say num = num + 1, you could say num += 1, a feature which I found very useful when using those languages. Is it possible to write some C code to do this? I would find it useful, although I am well aware I will have people chasing me down the road with stakes and torches for suggesting such blasphemy Joseph. |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
It would be easy to do, so that is not the problem. The real problem is that it would deviate from the "look and feel" of BASIC and clutter it with yet another convenience feature. In recent post I listed some of the criteria that I use for adding features to MMBasic and this one would break a few of them. Having said that, in a previous moment of weakness I added >> and << (from the C language) and += and -= (also from the C language) would be just as handy. I will look into it and figure out if there would be any unexpected consequences. Geoff Geoff Graham - http://geoffg.net |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2075 |
I love these shortcuts, << & >> make code so much easier to understand what is going on than the corresponding multiply or divide. I use bitwise operations in a lot of my code and they are really handy. += & -= would make great additions and is more flexible than ++ and -- num+=1 num++ <--- not really worth it as it is only one byte shorter and limits the increment my 2p |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9115 |
Can't support this unless all the versions are added *=, /=, >>=, <<=, and what about AND= and OR= and then the most useful ~ (bitwise inverse) so we can use "AND= ~n" and not trip over "NOT" which I keep doing This is Basic, so my view, FWIW, is to leave things as-is. |
||||
Vito Newbie Joined: 11/10/2016 Location: AustraliaPosts: 17 |
Where do you stop, go back to Dartmouth 1964? Why not line numbers and all other pre-historic dinosaur crap? Original Basics are long dead and gone, for obvious reasons and probably for above narrow minded thinking. Technology and programming continues to evolve on all other levels. On the other hand, there are other "relatively" easy more advanced choices such as (Arduino, mbed), Micropython, Lua, Javascript, etc. Time to move on. Rant over. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3801 |
Not very "advanced" considering it's over 50 years!! John |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9307 |
My 2c is that NUM=NUM+1 is the more conventional BASIC syntax. NUM+=1 is the same thing, but it is not a BASIC syntax - hence why it is also not in any of the other BASIC's, so I kinda have to agree with Matherp on this one. I hear what the OP is saying, but at the end of the day, is it really that hard to just use the former syntax? I might be missing something here, as I don't use C at all. Perhaps a set of Cfunctions could be written to do that, and include them in your code, then the MMBASIC core language does not need to change - you just add the feature you want. Just a thought. Smoke makes things work. When the smoke gets out, it stops! |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2075 |
Interesting that you draw that comparison; the very first basic "stole" bits and pieces from other languages... "From ALGOL it took the FOR...TO...STEP style loops..." https://en.wikipedia.org/wiki/Dartmouth_BASIC so tweaking by cherry-picking and adding the best from other languages is arguably, the purest form of enhancement for BASIC historically - which kind of plays into the OPs point (and we have precedence in MMBasic). This is a discussion about a form of BASIC. where do you suggest the move is to? Without enhancement there is no development beyond bug fixes. So we bang a stake in the ground and MMBASIC dev ends with the current version? To be honest - that isn't a bad deal... a bit defeatist but not a bad place for it to end. my 2p |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1873 |
My 2c worth. If I remember back to the Maximite in 2010, Geoff's idea was more for the hobbyist and he can correct me if that is not the case. As a hobbyist I understand Basic I have tried to learn C but I think I am too old. I know there are a lot of IT professionals in TBS but surely if they want the language to progress to a point where it no longer resembles Basic where does that leave all us hobbyists. They can always use C or whatever but the hobbyist has no choice, so for mine leave things as they are. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1101 |
I do feel the need to issue take Vito's "rant" above. Every language has its pluses amd minuses - as equally, they are all targetted to a general area of programming for which, over time, they are optimised. BASIC has advanced considerably over the time since K&K but the essential nature is still there - it is an easy to lean and quite 'natural' language in form and is arguably now quite 'modern' in it's current implimentation.. I agree with Grogster and matherp in that 'C' like features, while extremely powerfull are not really what BASIC is about - if you need all of the power and low level access to the iron, then C or similar is where you should go. As has been said by many others before, horses for courses. I love MMB - it does everything I need and I am in awe at the skills and committment of Geoff, Peter and others for their generosity in making such a powerful tool available. Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
I don't have a commitment to either historical basic or to a basic which imports syntax from other languages, but I do think the focus for development should be on what it has been for years--new features and new platforms rather than being able to do with fewer keystrokes what we already are able to do (not that there is anything wrong with that if Geoff choses to do it). Re: "Time to move on", anyone who thinks that mmbasic has not been moving on has not been paying attention. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Blasphemy indeed! I agree with Geoff and Peter, it does go against the look and feel of Basic and is something that can already be done easily in MMBasic. OK, I guess it would be more efficient when incrementing and decrementing a number. But if it is to be done my suggestion would be to use INC and DEC instead: INC A% DEC B% More like Assembly maybe but not C and definitely more understandable if you don't speak C. Bill PS I also agree with Panky, I am in awe of Geoff and Peter. Keep safe. Live long and prosper. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
Done: Jim VK7JH MMedit  MMBasic Help |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
OK Jim, That illustrates the point that it is easy to do in MMBasic. My point was that if "+=" was to be added to MMBasic that would be my preference. Bill PS I am in awe of you also. Keep safe. Live long and prosper. |
||||
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
Substitute "MMBasic" for "Britney"... |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
Hmmmmmm ... you guys aren't old enough, so far you haven't mentioned RPN, FLOW-MATIC, COBOL, FORTRAN, object oriented or SQL. In the beginning there was machine language, which was made readable by assembler. In 1949 Grace Hopper (PhD Yale) joined Eckert–Mauchly and assisted in the building of UNIVAC I, developed the A-O linker by 1952, specified FLOW-MATIC by 1954, and led CODASYL in the metamorphosis of FLOW-MATIC into the verbose COBOL in 1959, borrowing FORMULAS, the PICTURE clause, and an improved IF construction (which deprecated GOTO) from IBM's COMTRAN language. COBOL programs included four divisions, identification, environment, data and procedures. COBOL immediately began simplifying ... [X IS GREATER THAN Y] became [X GREATER Y] then [X > Y] ... [A > B AND A > C OR A = D] became [A > B AND C OR = D]. COBOL code was composed on Hollerith cards with 80 character lines where the columns had specific purposes ... 1-6 = line numbers, 7 = * comment, / = paginated comment, - = continuation line, D = debugging line. In 1953 John Backus specified FORTRAN. In 1979 he said "Much of my work has come from being lazy. I didn't like writing programs, and so, when I was working on the IBM 701, writing programs for computing missile trajectories, I started work on a programming system to make it easier to write programs." In 1964 Kemeny and Kurtz patched together BASIC by cleaning up the FORTRAN II syntax and removing the requirement to pre-declare variables to make it interact with students in a more immediate fashion. At MIT in 1961 Sketchpad appeared, then in 1966 LISP. These introduced OOP (Object Oriented Programming) which could incorporate procedures (methods) and data (instances) together into a single entity. This idea tends to confuse and upset people who learned procedural programming. In 1968 Fred Thompson at JPL used RETRIEVE to manage a database of office calculators. He and Jack Hatfield modified it into JPLDIS by 1973 which used a procedural language much like BASIC but incorporated persistent variables defined in the header of a database file independent of the program file. Then C Wayne Ratliff ported JPLDIS to an IMSAI8080 running PTDOS to improve his odds of winning the office football pool and called it VULCAN. It performed binary coded math and could evaluate string variables as if they were code. George Tate and Hal Lashlee formed Ashton-Tate and Ratliff ported VULCAN to CP/M which was marketed as dBase II, still written in assembly language. It begat dBase III, written in C and much slower, IV, V, Clipper, FoxBase and FoxPro. CA bought Clipper and abandoned it. Microsoft bought FoxPro and abandoned it. A much modified dBase variant is still being produced by a mysterious miniscule company called dBase LLC whose address is a vacant lot in Binghamton, NY. In 1973, Chamberlain and Boyce specified SEQUEL (SQL or squeel to big bluers)at IBM San Jose. It metamorphosized into DB2 and was adopted by Oracle. It is non-procedural and relies on the structure definition of a database to determine the procedures it must use. In other words, it implemented data driven programming which sort of sounds like OOP all over again. I see a trend here. Machine language is unreadable and incomprehensible to people with more than one eye. Assembler is readable with two eyes but still incomprehensible. COBOL code was overly complex and repetitive and detailed and verbose. FORTRAN was more compact but still complex. BASIC cleaned up some of the FORTRAN complexity. VULCAN and dBase used clean, simple, BASIC like interpreter code aimed at simplifying business problems. OOP and SQL took off in a new direction where the programmer does not have to produce explicit procedural code, the data dictates what the procedures will be. The trend is to move the programmer further away from the machine with its stack of registers and memory addresses blindly following procedural steps, and towards artificial intelligence determining how to solve procedural problems. "C" like shortcuts, like v++ instead of v=v+1, would tend to reverse this trend toward eliminating the hand written procedural program. I don't know if that's a good idea ... if all of us code geeks become as lazy as John Backus what would we do with all of our spare time????? Paul in NY |
||||
karjo238 Regular Member Joined: 12/10/2018 Location: New ZealandPosts: 54 |
Wowee, I really hit a spot there! I just want to reiterate here, because maybe I didn't make it clear in the original post, that the idea was a feature I'd find useful, but if it wasn't desirable by the community, that's absolutely fine too. Geoff, many thanks for taking the suggestion onboard. I look forward to the results of your deliberations in this matter. Again I stress this is your baby, and you really have the final say here, so I 100% abide by whatever decision you come to. I'd just like to reply to a couple of posts, if I may. MatherP and CaptainBoing: The amount of extra operators that you'd have to implement wasn't something I had considered when I wrote the post. If I had thought of that, I may well not have asked, because it's adding, as Geoff said, more complexity. TassyJim: I really do like the style of INC and DEC - it looks very much like a BASIC statement. My only real grumble is that quite often I need to add or subtract more than 1 from a variable, so it doesn't quite fill my needs the way that += or -= does. Having said that, the code you wrote is going in my code forthwith, so many thanks for that. Many thanks for the feedback given to this post. It's really nice to see people having a constructive conversation on a forum. I look forward to Geoff's feedback on this. I was going to also ask whether it would be possible to fill arrays in a single line, i.e.: Dim a a = (202,80,50,60,0,0,0) As opposed to: Dim a a(1) = 202 a(2) = 80 a(3) = 50 a(4) = 60 ... but I think I've done enough prodding for now... |
||||
Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
Naaaah ... prodding is fine around here. Geoff thought you should be able to do that and you can. From the manual: Paul in NY |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1611 |
Try: DIM a(4) = (0,202,80,50,60) ' Zero base array Bill Keep safe. Live long and prosper. |
||||
karjo238 Regular Member Joined: 12/10/2018 Location: New ZealandPosts: 54 |
Why did I not see this before? Many thanks for the prompt reply and the invaluable information! Time to get cracking, methinks.... |
||||
Page 1 of 4 |
Print this page |