? How to simplify code in programs? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
[Help Wanted] SmileBASIC Documentation Project

How to simplify code in programs?

  • #1 ✎ 24 DevinF06 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Is there any way to simplify code to easily be read by a program? for _=.to 1 'something ?"something",12 nextTo:FOR _=0 TO 1 'something PRINT "something",12 NEXT Posted Edited by DevinF06
  • #2 ✎ 98 niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies You'd have to write a program that can read the original code and simplify it... at which point you don't need to simplify it, because you just wrote a program that can already read it. Posted
  • #3 ✎ 24 DevinF06 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies I wanted it to be simplified so that some code can easily read it. Like so something can detect CONTROLLER 0 and prevent it. (It crashes SB.) Posted
  • #4 ✎ 1619 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Just complain to smileboom until they fix it lol Posted
  • #5 ✎ 274 Shelly
    I wanted it to be simplified so that some code can easily read it. Like so something can detect CONTROLLER 0 and prevent it. (It crashes SB.)
    I'm pretty sure that bug got fixed.
    Posted
  • #6 ✎ 931 Y_ack It's not like there aren't ways to: You can use newlines instead of statement separator (:), only the single-line IF syntax, not use functions, use whitespace consistently, consistently indent nested blocks... ...but you'd still have to write a parser, it would just be a parser that recognizes 85% of the SmileBASIC syntax instead of 99%. Posted
  • #7 ✎ 24 DevinF06 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Well, I just wanted to know so a program could read and replace code so it could be run line by line FOR I=0 TO 2 ?I NEXT I=0 ?I INC I ?I INC I ?I Posted
  • #8 ✎ 931 Y_ack Sure; what you're describing is called a compiler. Posted
  • #9 ✎ 24 DevinF06 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Huh. Posted
  • #10 ✎ 83 seggiepants You aren't explaining what you really want here. It sounds like you want two things. The first is a code formatter that would take exiting source code and reformat it. It would take things like ? and change it to PRINT, change . used as a number to 0 (why do people do this, they are both a single character), and add consistent padding and indentation levels. This would make other peoples code easier to read. The problem of course is that you can't do this with a bunch of simple search/replace calls. After all what happens if you use PRINT "How are you today?" and the formatter changes it to PRINT "How are you todayPRINT". In order to do it right you need to tokenize and parse the code then print it back out again in a standard form. The problem with that is of course that you are basically writing half of a compiler or interpreter. You are half way to writing SmileBasic in SmileBasic so you can SmileBasic while you are SmileBasic-ing (sorry couldn't resist the old meme). It would be sure nice to have that but probably no one wants to spend the time to write it. The second thing you post almost looks like loop unrolling which again heads off into compiler/interpreter territory. But, I don't think that is what you really want. Instead, what you really want is a nice debugger. Then you could put breakpoints on things, single step through code, and inspect variables, or add watches. That would be even nicer than the code formatter. Unfortunately, SmileBasic doesn't give you the hooks to write one. Instead we have two commands. In old school basic there were two more TRON and TROFF for trace on and off to trace variables in the program, and yes that is what the movie TRON is named after. Unfortunately, it doesn't look like SmileBasic gave us those. So we only have STOP and CONT/CONTINUE. Stop will halt execution of your code. Then you can try to print out variables manually in direct mode. Then when you are ready you can type CONT or CONTINUE to resume execution. TEST END DEF TEST VAR I FOR I = 1 TO 3 STOP PRINT I * I NEXT I END Then in direct mode you can RUN or hit the start button. It will say Break on 0:8 You can type in PRINT I to get a 1 then type CONT to have it continue. Repeat that three times and the program finishes. Unfortunately, that is all the tools we have to work with in SmileBasic. Well that and having a bunch of PRINT statements scattered throughout your code to write out status as things run.It is messy and primitive. If you have a terrible thing to debug you could try sending it over to your computer with PetitModem and then try to get it running under QB64. I think that one has a reasonable debugger, and is probably the closest computer equivalent of SmileBasic except it isn't really very close at all. The graphics and sound and such are all very much different between the two. I guess you have one more tool. Generate a key for the code, post a thread here, tell people what kind of problem you are having and where in the code. If you are lucky, the nice folks here may be able to help you fix the problem, or explain what is going on. Just don't abuse the help people provide, be thankful and patient, it can take a while. Posted
  • #11 ✎ 24 DevinF06 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies It was just a very complicated mess for me but if someone were to make this, any code editing/inserting via program is possible! (And with that, true multitasking is possible) Posted