Programming crisis : In software programming, can document really help us use the method correctly?

I feel that our current document in software development is not yet systematic enough to allow client code to avoid code violation only by reading document of callees, whether in object-oriented or process-oriented, It is hard to describe the impact of a method on object that is visible to the outside in the document, and the introduction of inheritance and polymorphism exacerbates this problem.

Programmers often use high-level understanding sentences to describe what the method does and how it affects the outside object, but such document is rarely useful for discovering code-level violation.

The ideal state I think is: “We can get the necessary information to deduce whether code violation will occur just only by reading document of callees.”, rather than searching necessary information in the source code after we fail to do the same in the document, or expecting to find all the problems that can not be deduced from the document by testing. But this ideal state seems to haven’t been achieved right now.

There is an abstract example code to explain a situation that client code cannot prevent code violation from occurring only by reading document of callees. The example code is an observer pattern situation and I cut out the code that wouldn’t prevent the problem from occurring.

class ClassA {
    /**
     * only be called once
     */ 
    public void foo() { /*...*/ }
}

// observer interface
Interface IClassB {
    /**
     * observer recive broadcast of subject.
     */ 
    public void foo(ClassA a);
}

class ClassB implements IClassB{
    /**
     * observer recive broadcast of subject. execute a.foo.
     */
    @Override 
    public void foo(ClassA a) {
        // ...
        a.foo();
        // ...      
    }
}

// subject
class ClassC {
    /**
     * broadcast to all observers, exectue ib.foo(a) for every observer;
     */
    public void foo(ClassA a) {
        // ...
        ib.foo(a);
        // ...
    }
}

// client code follow:
/*there is a ClassA instance whose foo method hasn't been called.*/
a.foo();
/*
According to the ClassC::foo document, we cannot know which subclass's IClassB::foo actcually be called, therefore, it is impossible to deduce what c.foo(a) will do from subclass document, then the client code is unable to know whether code violation will occur while executing c.foo(a). it is noted that client code is unable to know what kind of observers which c will broadcast to in many observer pattern applications.
*/
c.foo(a);

[repeat last comment:cIn the last line, according to the ClassC::foo document, we cannot know which subclass’s IClassB::foo actcually be called, therefore, it is impossible to deduce what c.foo(a) will do from subclass document, then the client code is unable to know whether code violation will occur while executing c.foo(a). it is noted that client code is unable to know what kind of observers c will broadcast to in many observer pattern applications.

The above is just one example of client code cannot prevent code violation from occurring only by reading document of callees, this problem must be also hidden in many situations. So, I want to know what happened, is there no perfect and reliable document specification? or is the ideal state I mentioned above was never pursued in programming field? How do I deal with this problem?

New contributor

ProgrammingCrisis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật