simplistic misunderstanding about ; + "" in a print - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: simplistic misunderstanding about ; + "" in a print (/showthread.php?tid=3045) Pages:
1
2
|
RE: simplistic misunderstanding about ; + "" in a print - SMcNeill - 09-19-2024 (09-19-2024, 08:03 PM)DSMan195276 Wrote:(09-19-2024, 01:07 PM)SMcNeill Wrote: No. The reason is just ease of translating.It's actually a behavior difference Imagine instead of string literals you're printing the results of some functions: PRINT "abc"; "def"; "ghi" <-- this will print in three separate statements like: PRINT "abc"; PRINT "def"; PRINT "ghi" Each one will test to see if they fit on the line, or if they need to word wrap, or if they need to perform a screen scroll. (Or, as you point out, if they produce an error along the way.) PRINT "abc" + "def" + "ghi" The above will join all those fragments together to make "abcdefghi" and then only perform the word wrap once on that whole joined together line of text. It'll only do the screen scrolling and such that one time as well. If anyone was thinking that I was saying those two methods are identical, then I apologize. They're not. In many cases, however, one can fairly freely swap between the two styles and not see much difference -- though there are times when BOTH ways might bite you in the butt, if you're not careful. Think about how long your possible strings are, and how they might word wrap, and then go from there. PRINT CHR$(34); "test"; CHR$(34) <-- as suggested by doppler, this MIGHT end up printing one of those three elements on the top line of text, and drop the others down to the next line. PRINT CHR$(34) + "test" + CHR$(34) <--- this would make certain that those three elements were combined. Either all three will fit up on the top line, or else all three elements will be printed to the next line. Now, if you're over on the left side of the line to start with, it's not going to matter as all three elements will fit on that single line to begin with. BUT, if you're only a few characters from the right edge of the screen, the two are going to have much different word wrap actions happen with them. They're not *exactly* the same, and it's not a case of "This is always better than that." Always remember to use what works best in your own particular use case. All we can really do here is just kind of draw attention to the behavior and hopefully make folks aware of what's going on so they can make informed decisions on what might work and perform best in their particular situations. RE: simplistic misunderstanding about ; + "" in a print - doppler - 09-20-2024 Wow what an enlightenment. What looks to be straight forward is nothing but. Depending of where the text output is going. It's one of those things that make me rack my brains trying to figure out "why it printed there" and "Not where I expected to go." Thanks for delving deep, into what looked like simple print function. Yes, I was following Steve on everything he said. And only because I have done plenty O/S "core function" programming. All of this is very inside information. Sometimes it's not very pretty. RE: simplistic misunderstanding about ; + "" in a print - TDarcos - 09-21-2024 (09-19-2024, 02:13 AM)SMcNeill Wrote: You have to remember, QB64 is a translator which turns BAS programs into C programs, and ... that's not always pretty.
(09-19-2024, 02:13 AM)SMcNeill Wrote: Just something to keep in mind, that most folks never consider. It's behind the scene translation at work on your code.Usually, for a high-level language programmer, you don't have to. It's been said that with most programming language compilers, it's not worth trying to improve your code by simplifying it, because the compiler already has improvement processes built into the compiler, like peephole optimization, loop unrolling, dead code elimination, expression simplification, etc., that there's not really that much you can do to provide a significant enough improvement to justify the time spent, and a better choice of thing to do for improvement is to see if there is a better algorithm for solving the problem your program is attempting to do than what you are using. Same for analyzing the assembly or machine code your program generates (or as in this case, C code), as most compiler writers either know the target instruction set (and operating system) very well, or they have people who do, and almost certainly better than you do. |