6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 14, 2024 7:24 am

All times are UTC




Post new topic Reply to topic  [ 103 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author Message
PostPosted: Mon Oct 14, 2024 12:33 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
barnacle wrote:
edit: the indentation is automatic as part of the listing. Leading spaces in a line are silently eaten.



An issue with that is that the indentation if your style of indentation which may not be to everyones liking. (If you ever release it)

My own BASIC auto-indents and I got some very vocal messages over it. Some people have very strong opinions...

Another minor issue I found was with my own TinyBasic - the interpreter chomps leading spaces (at a cost of time) but the input code doesn't (and can't easily) so repeated save/load/save/load will increase the indentation level. i'll fix it one day. Maybe. It'll depend on the save/load means though. If you can save a binary image then good, but if you re-purpose e.g. the LIST command to save it as TEXT then who knows...

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 14, 2024 3:03 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
Yeah, I appreciate that the indent might not suit all, but it's an easy change; it's just incrementing a counter if it sees an indentable keyword and lines thereafter are indented; the outdents are similar on the matching words (endif, while, next).

This is going to be simple: one instruction to the line (hence the need for endif).

The memory storage is line by line, but the initial line number is compressed to a uint16_t and followed by an eight-bit length byte; then the text: keywords are compressed to single bytes unless they're in quotes; again, for ease of interpretation.

Here's a view of the storage - the lines that say 'line number' aren't keywords so they're stored directly; they're not an error unless they're executed.
Code:
   10 for q = 1 to 10
   20   for p = 0 to 9
   30     print (q*10) + p
  127     line 127
  128     line 128
  129     line 129
 1024     line 1024
 2048     next
 4096   next
 5000 print "done"
> 50 ' this is a comment

0a 00 10 89 20 71 20 93 20 31 20 8a 20 31 30 0a  .... q . 1 . 10.
14 00 0f 89 20 70 20 93 20 30 20 8a 20 39 0a 1e  .... p . 0 . 9..
00 10 82 20 28 71 2a 31 30 29 20 2b 20 70 0a 32  ... (q*10) + p.2
00 17 81 20 74 68 69 73 20 69 73 20 61 20 63 6f  ... this is a co
6d 6d 65 6e 74 0a 7f 00 0c 6c 69 6e 65 20 31 32  mment....line 12
37 0a 80 00 0c 6c 69 6e 65 20 31 32 38 0a 81 00  7....line 128...
0c 6c 69 6e 65 20 31 32 39 0a 00 04 0d 6c 69 6e  .line 129....lin
65 20 31 30 32 34 0a 00 08 05 8b 0a 00 10 05 8b  e 1024..........

But then again, I don't expect anyone except me ever to run this; and I don't expect to run it often! It's more of a learning exercise.

Neil


Last edited by barnacle on Mon Oct 14, 2024 3:25 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 14, 2024 3:07 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
Rereading your message: if I use list it would save the spaces, then eat them and the line numbers when imported again, and then put back in by the next list command.

(Oh, and for those who like to type in upper case: it's happy with that, but it will always list in lower case because I don't :mrgreen: )

Neil


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 14, 2024 7:32 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8484
Location: Midwestern USA
barnacle wrote:
(Oh, and for those who like to type in upper case: it's happy with that, but it will always list in lower case because I don't :mrgreen: )

I’ve always had a rough time reading code that is all upper case.  The only upper-case in programs I write is in comments and, of course, character strings in which it is required.  I tend to not follow the C convention of using upper case to name constants and the like.

As for indenting, I don’t indent assembly language.  I use empty lines to delineate code blocks.  Been doing that for close to fifty years and I ain’t gonna change!  :D  I do indent in higher-level languages and shell scripts, for reasons I can’t explain.  :?

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 14, 2024 11:19 pm 
Offline
User avatar

Joined: Tue Feb 28, 2023 11:39 pm
Posts: 256
Location: Texas
drogon wrote:
barnacle wrote:
Some people have very strong opinions...


I would expect that the notion of TABs vs. Spaces and indention levels (or not at all) or if/when to move those braces around has start a good number of religious wars over the years.

One of my primary gripes about Python is that it forces you to indent, and heaven forbid you don't do it the way the interpreter wants you to, or you get a TAB mixed up with a space or something.

'cause you know, it's EASY to see when you have a TAB vs a few spaces in your text editor, right?


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 15, 2024 1:37 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8484
Location: Midwestern USA
Yuri wrote:
One of my primary gripes about Python is that it forces you to indent, and heaven forbid you don't do it the way the interpreter wants you to, or you get a TAB mixed up with a space or something.

Yep!  As far as I’m concerned, that “feature” of Python is just plain stupid!  Good languages don’t look at the “shape” of the code...they only look at the instructions and operands.

Quote:
'cause you know, it's EASY to see when you have a TAB vs a few spaces in your text editor, right?

Depends on the editor.  I use Ultra-Edit, which does indicate when whitespace is one or more tabs instead of actual blanks.  The editor in the Kowalski assembler/simulator can be configured to indicate whether whitespace is tabs or blanks.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 15, 2024 6:28 am 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
That's my major gripe with python - that, and a bizarre syntax which allows, for example, a function to return 3, 7, or "Thursday"... :roll:

Neil


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 15, 2024 7:45 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
Yuri wrote:
barnacle wrote:
Some people have very strong opinions...


I would expect that the notion of TABs vs. Spaces and indention levels (or not at all) or if/when to move those braces around has start a good number of religious wars over the years.


TABs (OCCAM, Python, Makefiles), (* ... *) Old BCPL, Braces (C, Modern BCPL, Ratfor, etc.), Begin/End (Algol, Pascal etc.) Start/Finish (imp77) and what not. Something is needed in a structured programming language where blocks of code extend over multiple lines. The holy war here is where do you place them - on the same line, line below at the same indent level, or line below indented. Personally I like my {}s aligned vertically under the controlling statement with the code indented, but 40+ years ago spaces cost both disk space and compile time so removing spaces, using TABs and putting them (begin/end, etc.) on the same line made sense...

Quote:
One of my primary gripes about Python is that it forces you to indent, and heaven forbid you don't do it the way the interpreter wants you to, or you get a TAB mixed up with a space or something.


Indentation is to replace the block start and end constructs. See above. Also; Programmer are lazy - why type BEGIN or use a { when you can just hit the TAB key...

Quote:
'cause you know, it's EASY to see when you have a TAB vs a few spaces in your text editor, right?


Why yes, it is. My editor of choice (vim) makes it very easy and even keeps the indentation. I can bind a key to a command that turns it on or off. I'm sure Emacs can do the same.

Note: I'm not a Python programmer - I really don't get it, but I do get the need for some sort of structure in our coding. I was taught that computers should make our lives easier - so in this case, the Python system ought to be able to work out the indentation level based on either spaces OR TABs OR any mixture of the 2 - but seemingly it doesn't. A failing IMO. It's a handful of lines in my own editor to de-tab a file - why can't python do that for you?

My own editor replaces TABs with spaces and the TAB key means: Take the cursor to the column position under the last non space character on the line above, OR move 2 spaces. It floats my boat.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 15, 2024 2:18 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8484
Location: Midwestern USA
drogon wrote:
TABs (OCCAM, Python, Makefiles), (* ... *) Old BCPL, Braces (C, Modern BCPL, Ratfor, etc.), Begin/End (Algol, Pascal etc.) Start/Finish (imp77) and what not. Something is needed in a structured programming language where blocks of code extend over multiple lines.

Oh, no question about that, at least to me.  Braces, brackets, parentheses, etc., are good choices for delineating code blocks, and are all “visible” and distinctive to the programmer.  Whitespace is a blur: is it a tab, an ASCII blank ($20), an extended blank ($A0), a non-printing character that leaves a blank space on the screen, or what?

barnacle wrote:
That's my major gripe with python - that, and a bizarre syntax which allows, for example, a function to return 3, 7, or "Thursday"... :roll:

Python almost seems to have been designed by a hippie who was sucking on a Cheech-and-Chong-sized joint.  :P  There are too many weird programming languages extant and Python is definitely in that category.  Try as I might (mostly due to faulty programming), I have never been able to write a function in “normal” languages that could possibly say 2 × 6 = Last Week:shock:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 15, 2024 4:50 pm 
Offline
User avatar

Joined: Tue Feb 28, 2023 11:39 pm
Posts: 256
Location: Texas
drogon wrote:
Quote:
'cause you know, it's EASY to see when you have a TAB vs a few spaces in your text editor, right?


Why yes, it is. My editor of choice (vim) makes it very easy and even keeps the indentation. I can bind a key to a command that turns it on or off. I'm sure Emacs can do the same.


Most decent editors do, but if you're a new programmer (of which I've had to deal with many), with some younger generations, I just get vapid stares when trying to explain the difference between a TAB and a space.

Quote:
Note: I'm not a Python programmer - I really don't get it, but I do get the need for some sort of structure in our coding. I was taught that computers should make our lives easier - so in this case, the Python system ought to be able to work out the indentation level based on either spaces OR TABs OR any mixture of the 2 - but seemingly it doesn't. A failing IMO. It's a handful of lines in my own editor to de-tab a file - why can't python do that for you?

My own editor replaces TABs with spaces and the TAB key means: Take the cursor to the column position under the last non space character on the line above, OR move 2 spaces. It floats my boat.

-Gordon


Structure is fine, and I don't have an issue with that, what gets me is that as I recall (from back in the day) the Python developer was intentionally trying to force people to indent in a way that they wanted. Which honestly seems like an absurd reason to make a major design choice in how a language functions; but that's my (not so) humble opinion.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 15, 2024 5:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
The way I've seen Python's use of significant whitespace is that it aims to link the way we the human readers see the code with the way the computer sees the code. One can squash a C, ALGOL, PASCAL program into a single line (barring preprocessor lines of course.) In those languages, it's the matching braces or BEGIN END words which delineate the structure. And so, it's all to easy to indent the program in a misleading way, which can lead to bugs and to unmaintainable code.

Python code cannot be indented in a misleading way - that's the advantage.

The disadvantage is that we may have different preferences for indentation, including tabs and spaces and including tools which make tabs and spaces difficult to see.

(Another disadvantage is that it's difficult to embed a python program as text within another program or other textual format - there needs to be a way to preserve lines and indentation.)

Remember that Python derives from a teaching language, where the aim is to introduce least new confusion, indeed to reduce confusion. A teaching language is meant to be easy to learn, easy for beginners, and of course easy to teach. These are all good things, but they may not sit well in an environment where everyone is expected already to be an expert and where other considerations are in play.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2024 5:52 am 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
BigEd wrote:
Python code cannot be indented in a misleading way - that's the advantage.


Well, perhaps not, but there is still the issue of tabs vs spaces and the confusion that can arise therefrom.

We have inherited a curious writing system where white space is metadata (and that applies equally to printed prose).

Neil


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2024 8:11 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10977
Location: England
My personal preference is never to insert or retain tabs in source code. Tab as a key on the keyboard, which the editor can use to insert an appropriate amount of space, is a good way to go, in my opinion.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2024 8:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8540
Location: Southern California
When we had very little memory, it was important to use tabs.  Not anymore.  When I want to post code here from many years ago, I have to use a function in my editor that replaces them with spaces, because the forum software doesn't interpret tabs the same way (columns 1, 9, 17, 25, etc., every 8th column staring with column 1), so the vertical alignment is very messed up if I don't fix it.  Now I have my editor set to do spaces when you press the TAB key.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2024 8:45 am 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
I tend to agree. As mentioned earlier, my code ignores spaces between the line number and the first keyword, and indents automatically on list. But it maintains spaces thereafter. It doesn't even know what a tab is at this point.

Code:
10 for q = 1 to 10
12345 for q = 1 to 10

both take 16 characters (2 bytes for line number, one byte line length, one byte each for 'for' and 'to', the text, and a terminating 0x0a. While
Code:
10forq=1to10
12345forq=1to10

uses five characters fewer - the spaces, ignoring the first.

Neil


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 103 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7  Next

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: