Lajos Juhász 294 Posted April 24 4 minutes ago, Lars Fosdal said: hey kept start index 1 to stay compatible with the short strings. At some point it might be desirable to change it, but ... well... Bye bye backwards compatibility. The mobile platform was a failed experiment to move string to be zero based. Share this post Link to post
dummzeuch 1506 Posted April 25 Since Delphi is kind of a legacy programming language nowadays, backwards compatibility is very important. You don't want to throw away millions lines of proven code because they don't work any more, or even worse, because they are now buggy. So trying to change strings to be zero based was a bad idea, even if it was "just for mobile platforms". 4 Share this post Link to post
Lajos Juhász 294 Posted April 25 During code review I can find cases when the developer assumes that the strings are zero based. Share this post Link to post
David Heffernan 2349 Posted April 25 1 hour ago, dummzeuch said: Since Delphi is kind of a legacy programming language nowadays, backwards compatibility is very important. You don't want to throw away millions lines of proven code because they don't work any more, or even worse, because they are now buggy. So trying to change strings to be zero based was a bad idea, even if it was "just for mobile platforms". I don't disagree with that point. My point is that it was a bad idea in the first place to make strings 1 based. Share this post Link to post
dummzeuch 1506 Posted April 25 (edited) 3 hours ago, David Heffernan said: I don't disagree with that point. My point is that it was a bad idea in the first place to make strings 1 based. Depends. Back then (in the 1970ies *1) it made a lot of sense to store strings that way. And when moving from Pascal to Delphi (>20 years later) and introducing longstrings (Delphi 2?) it already was a decision between keeping backwards compatibility to Pascal vs. being compatible with C. Edit: (*1: I'm not sure when strings were introduced into Pascal: Was it an addition in Turbo Pascal (1986) or did they already exist in the original Pascal?) Edited April 25 by dummzeuch Share this post Link to post
Dalija Prasnikar 1399 Posted April 25 1 hour ago, David Heffernan said: I don't disagree with that point. My point is that it was a bad idea in the first place to make strings 1 based. This was due to Turbo Pascal legacy. Share this post Link to post
Anders Melander 1795 Posted April 25 1 hour ago, Dalija Prasnikar said: This was due to Turbo Pascal legacy. ISO7185 (anno 1982) would like a word with you about that: Quote Any type designated packed and denoted by an array-type having as its index-type a denotation of a subrange-type specifying a smallest value of 1 and a largest value of greater than 1, and having as its component-type a denotation of the char-type, shall be designated a string-type. There weren't, to my knowledge, any formal standards before this (the ANSI standard came 1983) but strings has been 1-based since the beginning. Share this post Link to post
Dalija Prasnikar 1399 Posted April 25 2 hours ago, Anders Melander said: ISO7185 (anno 1982) would like a word with you about that: There weren't, to my knowledge, any formal standards before this (the ANSI standard came 1983) but strings has been 1-based since the beginning. That is in no contradiction with what I said, as TP started as extension of Standard Pascal. Anyway, 1-based string types never caused any problems until they introduced 0-based strings for mobile compilers and the whole hell broke lose. Share this post Link to post
Lajos Juhász 294 Posted April 25 57 minutes ago, Dalija Prasnikar said: Anyway, 1-based string types never caused any problems until they introduced 0-based strings for mobile compilers and the whole hell broke lose. Also until developers did not start to use multiple languages. 1 Share this post Link to post
JonRobertson 72 Posted April 25 15 minutes ago, Lajos Juhász said: Also until developers did not start to use multiple languages. Should that matter? I started learning Pascal 35 years ago and C the following year. Not once have I written c := (a < b) ? a : b; or if (a == b) { doSomething(); } while writing Pascal code. 1 Share this post Link to post
dummzeuch 1506 Posted April 25 1 hour ago, Lajos Juhász said: Also until developers did not start to use multiple languages. I have never ever confused Pascal Strings with C char* types. (And I have done quite a lot C programming at the beginning of my career, parallel to using Turbo Pascal and Visual Basic, before I chose Delphi as my main programming tool.) Share this post Link to post
David Heffernan 2349 Posted April 25 1 hour ago, JonRobertson said: Should that matter? I started learning Pascal 35 years ago and C the following year. Not once have I written c := (a < b) ? a : b; or if (a == b) { doSomething(); } while writing Pascal code. This is a strange post. The issue with multiple languages is the mix of zero based and one based indexing. Share this post Link to post
JonRobertson 72 Posted April 25 1 minute ago, David Heffernan said: This is a strange post. The issue with multiple languages is the mix of zero based and one based indexing. Different languages have different rules and syntax. Is that really an issue? I see the "issue" as developers using the incorrect syntax for the language they are currently using. If I toured Italy, I imagine my trip would be more enjoyable if I spoke Italian. Which I don't. Share this post Link to post
David Heffernan 2349 Posted April 25 36 minutes ago, JonRobertson said: Different languages have different rules and syntax. Is that really an issue? I see the "issue" as developers using the incorrect syntax for the language they are currently using. If I toured Italy, I imagine my trip would be more enjoyable if I spoke Italian. Which I don't. I mean I broadly agree. I was just trying to explain to Thomas what the post he was responding to actually said. For me it's crazy that dynamic arrays are zero based but strings are one based. Obviously I can see how we got here. Share this post Link to post
Dalija Prasnikar 1399 Posted April 25 7 minutes ago, David Heffernan said: For me it's crazy that dynamic arrays are zero based but strings are one based. Obviously I can see how we got here. Well, that discrepancy could have been solved with 1-based arrays. Delphi wouldn't be the first nor the last language having them. See: https://stackoverflow.com/q/9687039/4267244 Share this post Link to post
Brandon Staggs 278 Posted April 29 (edited) On 4/24/2024 at 2:09 PM, Lars Fosdal said: They kept start index 1 to stay compatible with the short strings. At some point it might be desirable to change it, but ... well... Bye bye backwards compatibility. They already tried that, at the same time somebody decided we didn't need any low-level string access in mobile compilers, right? That was a disaster, like the ARC attempt. Edit: I'm late to the party and others mentioned above. Personally, I think dreaming up ways to change legacy language idiosyncrasies in Pascal is a fool's errand. All you can really accomplish is alienating legacy projects from your updates. Edited April 29 by Brandon Staggs Share this post Link to post
FreeDelphiPascal 19 Posted June 6 On 4/24/2024 at 10:22 AM, David Heffernan said: for var item in arr do This is generally to be preferred, but sometimes you want the index as well as the item. In Python we write... The absence of such a feature, which also relies on tuple unpacking, makes such loops in Delphi less convenient. Come on David, you know it worth trading the "less convenient" way of programming in Delphi, for the speed we get from a Delphi program. I won't even dare to put Python in the same speed chart as Delphi.... 🙂 Share this post Link to post
David Heffernan 2349 Posted June 6 3 hours ago, FreeDelphiPascal said: Come on David, you know it worth trading the "less convenient" way of programming in Delphi, for the speed we get from a Delphi program. I won't even dare to put Python in the same speed chart as Delphi.... 🙂 You are trolling here right? Share this post Link to post