On Wednesday, 24 April 2019 21:12:54 UTC+3, Bart wrote:
> On 24/04/2019 18:06, Öö Tiib wrote:
> > On Wednesday, 24 April 2019 17:47:12 UTC+3, Bart wrote:
>
> >> Look at the question I posed at the end of my post: why does C++ (and a
> >> few others) make such a meal of it when in most languages you basically
> >> just use 'print'.
> >
> > Because C++ is often used for writing programs where are hundreds
> > of thousands or even millions of lines of code.
>
> Some of those other languages where 'print' or equivalent is one name,
> can also be used for large programs.
In C++ the "printf" is also one name when the team uses <stdio.h>. I
have very rarely seen anyone demanding usage of "::printf" then.
However when the team uses <cstdio> then "printf" is not required
to compile by standard so one should write "std::printf". Issue with
"printf" is that it is not type safe. Team should use static analysis
tools to verify that the format specifiers match (but better compiler
like gcc contain it already).
> > In namespaceless
> > programming languages the issues that it causes are avoided
> > either by having lot of little separate programs or by having the
> > namespace non-optional part of name like std_print,
> > big_print, bart_print, pig_print.
>
> I thought one of the advantages of a namespace feature is that you have
> the luxury of a bigger local context, even across a whole module,
> instead of just inside functions.
That certainly is so. The std just is not "local context" for anyone but
for standard library programmer.
> That should result in less need for uniqueness among names. But since
> you have to prefix each one with its namespace name, there seems little
> point. Why not forget namespaces, and use std_string instead of
> std::string, if you have to write it in full anyway.
When I read "string" then I assume that it is local name and am
annoyed when it is actually local alias of "std::string". Locally
all texts should have some local type. For example "CarModel"
that may be alias of "std::string". I have no idea why you want
to redeclare "basic sequence of bytes" (that "std::string" is)
locally in your "ropes" namespace as "ropes::string" and
to confuse the hell out of everybody.
> >> Suppose built-in types could also be part of a library, would std::int
> >> be acceptable?
> >
> > Worse, int is taboo to use in large number of projects
> > (both C and C++). It will be rejected by review with verdict:
> > "Should use int32_t." Now about int32_t there is indeed
> > difference. When author included <cstdint> then they
> > should use std::int32_t; when author included <stdint.h>
> > then they should use int32_t.
>
> Meanwhile the rest of the world just uses int32 or i32 and everyone
> knows what they mean. (How many bits wide? How about taking a wild guess...)
>
> Why is it just C++ that gets its knickers in a twist about this?
In C++ we have had some trouble when ::u32 and ::i32 were typedefs
of "unsigned long" and "signed long" by platform vendor and
"unsigned int" and "signed int" by vendor of third party module.
Typical "bleeding edge" crap from moronic American chip
manufacturer. Typical silver bullet" module bought for $ 120K
by fatsos. Both wrong! But we *must* use those. :(
I still support if team wants to use such names as aliases
of std::uint32_t and std::int32_t ... even if we have to maintain
the third party "silver bullets" as result.
> >> How about operators like "+"; how do I know that the "+" here:
> >>
> >> a + b
> >>
> >> is either standard "+", or the "+" from library X, or the "+" from Y?
> >>
> >> Should all such code be written as a std::+ b, or a X::+ b?
> >
> > No. Binary operators should be either inside class of first argument
> > or inside same namespace with argument types. Compiler will
> > search from those places and so should programmer assume
> > that those are there.
> >
> >> And if a and b are globals, should it be:
> >>
> >> X::a std::+ Y::b
> >>
> >> just to remove all doubt?
> >
> > Globals don't scale anyway because one has to put locks around
> > accesses of those to avoid race conditions. Do you program little
> > hello word style apps only?
>
> No. I use a language (not C++) that has namespaces, but it's rare that I
> need specify one with a prefix. If there's an ambiguity because the same
> two identifiers are visible, then the compiler will tell me.
>
> (And when I do need to use one, I use ".", not "::", which is easier on
> the eye.)
Ok. Note that I asked couple questions you did not ask:
You wrote:
> Look at file systems, which can also have long absolute paths. But most
> of the time you don't need that path to distinguish F from A/F or B/F or
> C/F. F is usually taken to be ./F, and usually you don't need to write
> the "./".
>
> Using std:: is like insisting all file names must be written in
> canonical form with absolute paths. What a PITA that would be.
And I answered:
Can't parse that analogy. I am typically programming in "different
directory" than std lets say, in namespace named x and in member
function of class x::Y sure I won't qualify x::F there, just write F.
But how is the std::F suddenly also F for me?
Can you please explain it or at least agree that the analogy was not
best thought thru?