On 21/09/2021 08:39, David Brown wrote:
> On 20/09/2021 22:38, Bart wrote:
>> But to talk with some knowledge about how Print might be better
>> implemented in any language, you really need to have tried implementing
>> Print within a language, and specifically implementing it as a built-in
>> feature
>
> No one cares about how easy or hard it is to implement.
You're changing the goalposts. You said my opinion wasn't an informed
one, when I was talking about the deficiences of both cout and printf
approaches.
> A BASIC-style print statement is fine
> for BASIC-style languages - typically designed to be quick and simple
> for easy tasks, but unsuitable for bigger work or more complex work, or
> programs that don't fit into the simple sequence of start program, read
> files and/or keyboard, print to screen and/or files, stop program.
What can 'cout' or 'printf' do that an easier-to-use and better designed
Print can't do? This is an example bit of C++ posted a couple of days ago:
CMT:
std::cout << sizeof(__int64) << "\n";
std::cout << sizeof(__m128) << "\n";
std::cout << foo_64.is_lock_free() << "\n";
std::cout << foo_128.is_lock_free() << "\n";
I might be missing something, but is there any reason why something like:
println sizeof(__int64);
println sizeof(__m128);
println foo_64.is_lock_free();
println foo_128.is_lock_free();
wouldn't cut it? Too sensible? Too uncluttered? Might leave too many
people thinking, where's the catch? Because all that extra crap in C++
must do something important, right?
> But for a language that supports multiple types, formatting,
> translations, redirected outputs, systems without a console, etc., then
> a simple print statement won't do. It is both too much, and too little.
You're making this up aren't you?
Simple Print doesn't mean an inability to do anything. It means being
able to do most of it, but in a simpler manner with a lot less typing!
> In fact, /no/ single solution will do everything.
But it might do 90% of it.
> When you think you
> have "/the/ answer" to a coding or programming language problem, you are
> almost guaranteed to be wrong - and you, Bart, think you have all the
> answers.
Some things are just no-brainers.
> So a good, serious programming language does not provide a "print"
> statement.
Yeah. And the better ones also do away with mutability. And global
variables (see new 'pen' language). And loops. And of course goto.
>> Here, anyone can judge for themselves (although I doubt they'll be that
>> open minded in a C++ group):
>>
>> 20 print i, sqr(i)
>>
>> std::cout << i << " " << sqrt(i) << std::endl;
>>
>> The first line is from decades-old BASIC. The second line, which also
>> needs iostream and math.h includes, is from latest C++.
>>
>
> The first version is easist for a quick and dirty script.
Most of my uses of Print are quick and dirty:
* Because I add and remove such statements extensively for debugging, so
the total number of Prints written are much greater than than the number
of static Print statements in a finished program
* I also use it a lot for large numbers of throwaway programs, test
programs, code posted on forums, etc, in a variety of languages.
C's printf is poor in that regard, but I think C++'s cout might just pip
it. However Zig's print facilities I think are even worse; once you've
figured out how to do it once, you have to keep that example locked away
for future reference!
> The second
> is better for more serious programming.
So give me an example of serious programming where:
println X
is no good at all, and you're better off with:
std::cout << X << "\n";
> Oh, and if your "sqr" is a language built-in function for square roots,
> then that demonstrates another reason why serious languages avoid
> built-in functions. The name is wrong, and changing the library is
> vastly easier than changing the language.
SQR comes from BASIC (most languages use 'sqrt'). Many also have such
abilities built-in, because it's convenient.
In mine, sqrt is an operator. You don't need to include or import
anything; it's just there. And usually mapped to an x64 'sqrtsd'
instruction, but that's up to the backend.
Now look at the abs() function, and you realise why it is BETTER to have
such things properly built-in, and not just a bunch of templates. In C,
you have these variations:
abs(x) // these need stdlib.h
labs(x)
llabs(x)
fabs(x) // these need math.h
fabsf(x)
Maybe there's some more, I don't know. I just have 'abs', and it works
on any suitable type, because it's a unary operator like 'negate'.
> And there you have it.
>
> With your personal language and tools, if you want to change the way the
> spacing or formatting works, you change the language and the
> compiler/interpreter. With real languages, the programmer changes the
> code they write to change the formatting.
You say you like Python.
Python also injects implicit spaces and implicit new lines. But that's
OK, even though it is a PITA to figure out how to suppress them.
But C++, where it is a PITA to have to add explicit spaces and newlines,
is also fine.
The only place it isn't fine, apparently, is my language, where I have
implicit spaces and explicit newlines!
There /is/ a simple way to suppress spaces, but if you don't know what
it is, then instead of writing:
print "ABC","DEF" # ABC DEF
you have the option to just split the print into two:
print "ABC"; print "DEF" # ABCDEF
Because of how it works. In Python, you HAVE to go and look this up, as
splitting a print will just insert a newline instead of a space.
(Space suppression between my print items uses: ",," instead of ",".
When that gets too ugly, then you use formatted print.)
> Contrary to some experts' views, I have nothing against BASIC. I
> learned to program in BASIC, in several dialects - the "B" stands for
> "Beginners'". But then I grew up, and understood that while languages
> like BASIC can undoubtedly be good for a few hundred line programs, they
> are rarely a good choice for more serious work.
I want to port an algorithm which is expressed in both language A and
language B, into a new language.
Suppose A and B were C++ and BASIC; which do you think would be simplest
to work from?
The chances are that it will be BASIC, since most of its features exist
also in many other languages.
With C++, especially if written by Bonita Montero, it would likely mean
first implementing a dozen C++ libraries that it will depend on, and
disentangling a mess of arcane syntax.
You shouldn't really write off a language for language for being too simple.
It actuality, that simpler language, more likely to use mostly simple,
universal features, might be something like Lua or Python. Or even C,
provided the author hasn't gone mad with macros.