C++ Logo

sg20

Advanced search

Re: [isocpp-ext] namespace composition

From: Bjarne Stroustrup <bjarne_at_[hidden]>
Date: Mon, 1 May 2023 12:56:51 -0400
I know it can be done, but it's not what I want to do.

We could have a long philosophical discussion about that, but I don't
think this is the venue for that.

On 5/1/2023 5:56 AM, Peter Sommerlad (C++) wrote:
> Hi Bjarne,
>
> I am late on this thread, but I teach C++ in a way, where indexing is
> (almost) never used, at least not for beginners. So I never felt the
> need to ask for range checking (iterator invalidation is another
> unfortunately related topic).
>
> I teach beginners (who know other programming languages a bit, such as
> Java or Python) an algorithm-first approach, similar (but now much
> easier thanks to generic lambdas) as Barbara Moo and Andrew Koenig in
> "Accelerated C++".
>
> Using a decent IDE (which I unfortunately no longer can maintain:
> Cevelop) with some student-oriented static analysis checks also helped a
> lot.
>
> Also using namespace std never was a real problem, especially after we
> implemented namespace- and qualified name- related refactorings.
>
> I understand this might not help your situation, but at least I found my
> workaround.
>
> Regards
> Peter.
>
>
>
> Bjarne Stroustrup via Ext wrote on 28.04.23 21:12:
>> This question is in the context of teaching novices. For experienced
>> programmers, I have workarounds.
>>
>> I would like to make all of the standard library available
>>
>> as a module based on module std
>>
>> with guaranteed range checking
>>
>> without requiring students to write std:: all the time
>>
>> and add a few supporting features
>>
>> I have successfully done that for tens of thousands of students over
>> more than a decade using some disgusting macro tricks. Think
>>
>> #define vector My_checked_vector
>>
>> Having guaranteed range checking is a great help to students. I estimate
>> that it eliminates more than 50% of crashes and lots of frustration.
>>
>> Modules and disgusting macro tricks don't go well together
>>
>> I was planning to use
>>
>> using vector = My_checked_vector
>>
>> but I can't find a way for that to work together with
>>
>> using namespace std;
>>
>> Am I being blind?
>>
>> Any suggestions?
>>
>> I can get away with a single #using "PPP_support.h" containing three
>> macros, but I would really like to avoid that.
>>
>> I suspect the fundamental problem is that there is no way of composing a
>> module or a namespace saying "I want all of Foo, except that I want my
>> own versions of Foo::X and Foo:Y." I would *love* to be proven wrong
>> about that. The original namespace design had such a mechanism, but I
>> have not been able to get it to work.
>>
>> _______________________________________________
>> Ext mailing list
>> Ext_at_[hidden]
>> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/ext
>> Link to this post: http://lists.isocpp.org/ext/2023/04/21140.php
>

Received on 2023-05-01 16:56:54