Selective friends in C++. (10th May 2018)
- Record Type:
- Journal Article
- Title:
- Selective friends in C++. (10th May 2018)
- Main Title:
- Selective friends in C++
- Authors:
- Márton, Gábor
Porkoláb, Zoltán - Abstract:
- Summary: There is a strong prejudice against the friendship access control mechanism in C++. People claim that friendship breaks the encapsulation, reflects bad design, and creates too strong coupling. However, friends appear even in the most carefully designed systems, and if it is used judiciously (like using the attorney‐client idiom), they may be better choice than widening the public interface of the class. In this paper, we investigate how the friendship mechanism is used in C++ programs. We have made measurements on several open source projects to understand the current use of friends. Our results show various holes and errors in friend usage, like friend functions accessing only public members or not accessing members at all or the class, which declare friends has no private members at all. The results also show that friend functions actually use only a low percentage of the private members they were granted to access, which is a source of errors. These results have motivated us to propose a selective friend language construct for C++, which can restrict friendship only to well‐defined members. Such a new language element may decrease the degradation of encapsulation and significantly increase the diagnostic capacity of the compiler. We have created a proof‐of‐concept implementation based on the LLVM/Clang compiler infrastructure to show that such constructs can be established with a minimal syntactical and compilation overhead.
- Is Part Of:
- Software, practice & experience. Volume 48:Number 8(2018)
- Journal:
- Software, practice & experience
- Issue:
- Volume 48:Number 8(2018)
- Issue Display:
- Volume 48, Issue 8 (2018)
- Year:
- 2018
- Volume:
- 48
- Issue:
- 8
- Issue Sort Value:
- 2018-0048-0008-0000
- Page Start:
- 1493
- Page End:
- 1519
- Publication Date:
- 2018-05-10
- Subjects:
- C++ programming language -- encapsulation -- friend -- selective friend
Computer software -- Periodicals
Computer programming -- Periodicals
Computer programs -- Periodicals
005.3 - Journal URLs:
- http://onlinelibrary.wiley.com/ ↗
- DOI:
- 10.1002/spe.2587 ↗
- Languages:
- English
- ISSNs:
- 0038-0644
- Deposit Type:
- Legaldeposit
- View Content:
- Available online (eLD content is only available in our Reading Rooms) ↗
- Physical Locations:
- British Library DSC - 8321.453000
British Library DSC - BLDSS-3PM
British Library STI - ELD Digital store - Ingest File:
- 6999.xml