? 🅱️ode 🅱️ritique (Page 4) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

🅱️ode 🅱️ritique

1 2 3 4 5
  • #61 ✎ 46 incvoid
    The constant death march toward modernization is a dangerous effort to optimize the future at the cost of our past. I propose a countermethod, instead adopting the styles of assembly; you can see there is a kind of beautiful clarity in the bones of the machine, in full view as the onion skins are pullled away. @_ENTRY MOV SP$,@HELLO GOSUB @PUTSTR PUTCHR 10 'LINE ENDING END @PUTSTR POPB A IF EQU(A,0) THEN RETURN PUTCHR A GOTO @PUTSTR @HELLO DATA "Hello, world!",0 DEF MOV _,L RESTORE L READ SP$ SP$=SP$+CHR$(0) END DEF POPB _ A=ASC(SHIFT(SP$)) END DEF EQU(A,B) RETURN A==B END DEF PUTCHR V PRINT CHR$(V); END
    not familiar with _ as a parameter name or how its treated at a compile time.. but shouldnt some of the lines be READ _ _=_ + CHR$(0) ... _=ASC(SHIFT(SP$)) POPB dedicated to popping from sp$...like stack pointer string pointer.. in that case mov doesnt need SP$ as a parameter. Wouldnt thT be more like loadsp or some flavor.
    Posted
  • #62 ✎ 340 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength
    The constant death march toward modernization is a dangerous effort to optimize the future at the cost of our past. I propose a countermethod, instead adopting the styles of assembly; you can see there is a kind of beautiful clarity in the bones of the machine, in full view as the onion skins are pullled away. @_ENTRY MOV SP$,@HELLO GOSUB @PUTSTR PUTCHR 10 'LINE ENDING END @PUTSTR POPB A IF EQU(A,0) THEN RETURN PUTCHR A GOTO @PUTSTR @HELLO DATA "Hello, world!",0 DEF MOV _,L RESTORE L READ SP$ SP$=SP$+CHR$(0) END DEF POPB _ A=ASC(SHIFT(SP$)) END DEF EQU(A,B) RETURN A==B END DEF PUTCHR V PRINT CHR$(V); END
    not familiar with _ as a parameter name or how its treated at a compile time.. but shouldnt some of the lines be READ _ _=_ + CHR$(0) ... _=ASC(SHIFT(SP$)) POPB dedicated to popping from sp$...like stack pointer string pointer.. in that case mov doesnt need SP$ as a parameter. Wouldnt thT be more like loadsp or some flavor.
    I'm guessing _ means a generic variable with any use and name and is shorter to type than "input"
    Posted
  • #63 ✎ 1037 Yttria it's just a legal identifier that happens to look funny calm down Posted
  • #64 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself yeah, how would you like it if everyone would not stop talking about your name just because it has too many underscores in it? Posted Edited by 12Me21
  • #65 ✎ 1056 snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements
    it's just a legal identifier that happens to look funny calm down
    Yes, in SB _ is just a valid identifier that doesn't actually mean anything special. VAR _ = 10 PRINT _ '10 It looks a bit weird in the given code, I suspect, because I'm passing a string to an identifier without a $ on it. But in SB, function params aren't typed until there's a value passed to them (or, params take the type of the value passed to them.) DEF PLEN V PRINT LEN(V) END PLEN "ABC" '3 PLEN 123 'runtime type mismatch The type mismatch error in this code doesn't come from the fact that we're calling PLEN with an int, it comes from the fact that PLEN tries to call LEN with an int. Now stop talking about it. Also please be aware that you are on a joke thread and the code posted was supposed to look like bad assembly.
    Posted Edited by snail_
  • #66 ✎ 171 banana RNG Hidden Easter Eggs Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength please review my code why it dont work exec "prg1:lib" main = IO() signal(main, print("hello")) run(main, 9696195221+λ) Posted
  • #67 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself
    please review my code why it dont work exec "prg1:lib" main = IO() signal(main, print("hello")) run(main, 9696195221+λ)
    There's a missing semicolon
    Posted
  • #68 ✎ 986 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies Hey try to fix this one: DEF FAC(V1) VAR RET FOR I=V1 TO 1 STEP -1 RET=RET*I NEXT RETURN RET END It's supposed to be a factorial function but it always returns 0 I actually fixed this but in the chat people wanted me to put this here, so don't judge I also have a loading screen, but it doesn't seem to load anything. CLS ?"Loading sprites" WAIT 480 This is obviously a joke Posted Edited by random_god
  • #69 ✎ 481 chicken
    Hey try to fix this one It's supposed to be a factorial function but it always returns 0
    DEF FACK(IN) IF IN > 2 THEN RETURN IN * FACK(IN-1) ELSEIF IN < -1 THEN RETURN IN * FACK(IN+1) ELSE RETURN IN ENDIF END edit:ok fine i make good-er
    Posted Edited by chicken
  • #70 ✎ 1037 Yttria
    Hey try to fix this one: DEF FAC(V1) VAR RET FOR I=V1 TO 1 STEP -1 RET=RET*I NEXT RETURN RET END
    The problem is that it isn't fast enough: DEF FAC(V1) VAR RET=MAX(V1,1) FOR I=V1-1 TO 2 STEP -1 RET=RET*I NEXT RETURN RET ENDThis drops like, 2 redundant iterations. Except that the factorial of any inputs > 12 won't even fit in an int32 (and is defined only for nonnegative integers), so we can implement it as a lookup table with little space overhead instead. @SEQ_FACT DATA 1,1,2,6,24,120,720,5040,40320,362880,3628800,479001600 DIM FACT_TBL[0] COPY FACT_TBL,@SEQ_FACT DEF FASTFACT(N) IF N>=0 && N<12 THEN RETURN FACT_TBL[N] RETURN 0 ENDBehavior for unsafe inputs isn't well defined, so you might want to STOP instead of returning -1 or 0 or something... FACT_TBL[n] can be indexed directly when you don't even need the safety check.
    Posted Edited by Yttria
  • #71 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself DEF FACT N OUT F F=479001600 FOR N=N+1 TO 12 F=F DIV N NEXT ENDRuns in O(12-n) Posted Edited by 12Me21
  • #72 ✎ 114 Autz64 QSP Contest 1 Winner I won the first SmileBASIC Source QSP Contest! Programming Contest End of 2017 Contest Participant I participated in the SmileBASIC Source End of 2017 Contest! Programming Contest Deep Sleep Hidden Website This should do the trick, returns -1 if N>12 so you can figure out a workaround with that value DEF FAC(N) IF N>1 THEN RETURN (N*FAC(N-1))*(N<13)+(-1*(N>12)) ELSEIF N>0 THEN RETURN 1 ENDIF RETURN 0 END Posted
  • #73 ✎ 1037 Yttria From "C Struct Interpreter" @ STRING.LIB: COMMON DEF ISDIGIT (A$) FOR I = 0 TO LEN(A$) - 1 IF ASC(A$[I]) >= 48 AND ASC(A$[I]) <= 57 THEN RETURN TRUE ELSE RETURN FALSE ENDIF NEXT I ENDshould be COMMON DEF ISDIGIT(C$) RETURN C$>="0" && C$<":" ': in case C$ really is string END likewise, COMMON DEF ISLETTER (A$) FOR I = 0 TO LEN(A$) - 1 IF ASC(A$[I]) >= 65 AND ASC(A$[I]) <= 90 THEN RETURN TRUE ELSEIF ASC(A$[I]) >= 97 AND ASC(A$[I]) <= 122 THEN RETURN TRUE ELSE RETURN FALSE ENDIF NEXT I END should be COMMON DEF ISLETTER(C$) RETURN (C$>="A"&&C$<"[") || (C$>="a"&&C$<"{") END Noting that: 1) string comparisons are valid in SB 2) the FOR loops reek of copy/paste code smell, only first char will be checked 3) basic ASCII comparisons can benefit from boolean zen 4) AND/OR are bitwise operators; logical &&/|| versions are preferred here Another: COMMON DEF UPPER (A$) T$ = "" FOR I = 0 TO LEN(A$) - 1 IF ASC(A$[I]) >= 97 AND ASC(A$[I]) <= 122 THEN N = ASC(A$[I]): N = N - 32 T$ = T$ + CHR$(N) ELSE T$ = T$ + A$[I] ENDIF NEXT I RETURN T$ END COMMON DEF UPPER(A$) VAR T$=A$*1 'clone A$ VAR N FOR I=LEN(A$)-1 TO 0 STEP -1 'iterate backwards N=ASC(T$[I]) IF N>=97 && N<=122 THEN T$[I]=CHR$(N-32) NEXT RETURN T$ END Noting that: 1) every string concatenation may allocate a new string, which the IF/ELSE *guarantees* to risk for every character in A$. Allocating T$ with the correct length initially avoids this, but we can do better... 2) if we clone A$ (are we not allowed to edit destructively, anyway?) into T$ then we don't even need to modify characters outside of the lowercase range: they're already there 3) everything involving the comparison is so redundant... three guaranteed string subscript and ASC() calls every iteration, subtracting in another statement for no reason, doing the CHR$() in another operation... Posted Edited by Yttria
  • #74 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself DEF UPPER(S$) RETURN DIALOG(S$,"") END Posted
  • #75 ✎ 171 banana RNG Hidden Easter Eggs Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength This is the worst code I've ever wrote. (view it with code wrap enabled) [QRF4D3V3] (key because I dnot have 3.6.0 to screenshot) Posted Edited by banana
  • #76 ✎ 1828 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself
    This is the worst code I've ever wrote (view it with code wrap enabled) [QRF4D3V3] (key because I dnot have 3.6.0)
    You should use ACLS instead of CLS, just in case
    Posted
  • #77 ✎ 171 banana RNG Hidden Easter Eggs Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
    This is the worst code I've ever wrote (view it with code wrap enabled) [QRF4D3V3] (key because I dnot have 3.6.0)
    You should use ACLS instead of CLS, just in case
    You're right, thanks much.
    Posted
  • #78 ✎ 171 banana RNG Hidden Easter Eggs Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength AAA why me game dnot wor?k int PLAUYER% WHILE 1 { console.log(FORMAT$("%d",math.random(10))); SPVAR PLAUYER%,1 (SETQ A (+1 A)) puts A unless A%2 WEND Posted
  • #79 ✎ 986 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies
    AAA why me game dnot wor?k int PLAUYER% WHILE 1 { console.log(FORMAT$("%d",math.random(10))); SPVAR PLAUYER%,1 (SETQ A (+1 A)) puts A unless A%2 WEND
    Uhh you kinda went WHILE 1{ WEND instead of WHILE 1{ } or WHILE 1 WEND I'm only judging this off of what I've seen people do in other languages, I don't actually know how the {} thing works.
    Posted
  • #80 ✎ 171 banana RNG Hidden Easter Eggs Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength
    SNIP
    Uhh you kinda went WHILE 1{ WEND instead of WHILE 1{ } or WHILE 1 WEND I'm only judging this off of what I've seen people do in other languages, I don't actually know how the {} thing works.
    I just mixed C, JavaScript, Ruby, Lua, LISP and SmileBASIC in one, horribly looking snippet lol
    Posted
1 2 3 4 5