검색결과 리스트
책 정리/Code Complete 2nd에 해당되는 글 4건
- 2009.03.18 [Code Complete 2nd/e] Words - 1
- 2009.03.18 Code Complete - Eng Version Doc
- 2009.03.09 Part 2 - Chapter 8 Defensive Programming
- 2009.03.08 Part 2 - Chapter 6. Class Handling
글
[Code Complete 2nd/e] Words - 1
consistent <-> inconsistent
Someone who is consistent always behaves in the same way, has the same attitudes towards people or things, or achieves the same level of success in something.
Becker has never been the most consistent of players anyway.
his consistent support of free trade.
If one fact or idea is consistent with another, they do not contradict each other
This result is consistent with the findings of Garnett & Tobin.
ownership = Ownership of something is the state of owning it.
sufficient <-> insufficient
If something is sufficient for a particular purpose, there is enough of it for the purpose.
map 일치시키다.
invaluable
pass off an exception
If an event passes off without any trouble, it happens and ends without any trouble.
The main demonstration passed off peacefully.
Such an approach says
centralized
ensure
repository
'책 정리 > Code Complete 2nd' 카테고리의 다른 글
Code Complete - Eng Version Doc (0) | 2009.03.18 |
---|---|
Part 2 - Chapter 8 Defensive Programming (0) | 2009.03.09 |
Part 2 - Chapter 6. Class Handling (0) | 2009.03.08 |
글
Code Complete - Eng Version Doc
please download...
'책 정리 > Code Complete 2nd' 카테고리의 다른 글
[Code Complete 2nd/e] Words - 1 (0) | 2009.03.18 |
---|---|
Part 2 - Chapter 8 Defensive Programming (0) | 2009.03.09 |
Part 2 - Chapter 6. Class Handling (0) | 2009.03.08 |
글
Part 2 - Chapter 8 Defensive Programming
2. To check all input parameters.
3. To decide how to process with incorrect input.
If Assertion is true, it means everything works hos I expect.
If not, it'll assert to show there is an error in a program.
Ex in JAVA ) assert denominator != 0 : "denominator is unexpectedly equal to 0.";
It's used to find out unexpected condition and assumptive things.
Ex ) 1. input or output is in expected range.
2. File or Stream checks whether it's open or close.
3. Either file or stream is opened as readable, writable, or readable/writable mode.
4. Whether a pointer is null
and so on...
The purpose is to be used during development or maintenance period for programmer.
Ex ) To make assertion macro in C++
#define ASSERT( condition, message ) { \
if ( !(condition) ) { \
LogError( "Assertion failed: ", \
#condition, message ); \
exit( EXIT_FAILURE ); \
} \
A Guide how to use Assertion
1. Don't write executable code in Assertion.
In this case, it can be unable to execute.
If you don't compile Assertion, code which is in Assertion isn't compiled.
Safe Ex ) actionPerformed = PerformAction()
Debug.Assert( actionPerformed )
3. To process an error after assertion.
But it depends on a sort of programs.
Ex) The case of calculation, you return 0.
The case of operation of string or characters, u return empty one.
The case of a pointer, u return an empty pointer.
The case of drawing routine, u draw previous or basic color.
The case of X-RAY showing, u terminate a program. -> It's bad to show
incorrect value.
You should seek next another data or return the same data as before.
Ex) Thermometer or the color of sth in game.
'책 정리 > Code Complete 2nd' 카테고리의 다른 글
[Code Complete 2nd/e] Words - 1 (0) | 2009.03.18 |
---|---|
Code Complete - Eng Version Doc (0) | 2009.03.18 |
Part 2 - Chapter 6. Class Handling (0) | 2009.03.08 |
글
Part 2 - Chapter 6. Class Handling
Abstract Data Type
Once you understand ADT, you can make easy class to make in the beginning and to change in the future.
ADT is not int or float type which are defined ( or fixed ). It's a data type whice is made by developer such as struct or class.
The advantages :
-
Changing doesn't influence the whole program.
-
It's easy to advance a program.
-
Apparently It's easy to understand. and so on...
Better Class Interface
-
To make consistent interfaces.
Inappropriate Example
-
- class EmployeeCensus : public ListContainer{
-
public:
-
void AddEmployee( Employee employee );
-
void RemoveEmployee( Employee employee );
-
Employee NextItemInList();
-
Employee FirstItem();
Employee LastItem();
- }
In this case, 2 functions are about Employee. 3 functions are about List. It's not consistent abstract.
Appropriate Example
- class EmployeeCensus : public ListContainer{
-
public:
-
void AddEmployee( Employee employee );
-
void RemoveEmployee( Employee employee );
-
Employee NextEmployee();
-
Employee FirstEmployee();
Employee LastEmployee();
-
private:
-
ListContainer m_EmployeeList;
- }
The Abstraction is all about Employee.
2 To provide a pair of service which has an opposite function.
If there is a function which turn on the radio, we might need a function which turn off the radio.
But make sure that the opposite function is needed. So you should check it.
-
During maintenance, be careful to mess abstraction.
SqlQuery GetOueryToCreateNewEmployee() const; ~~~
Its' level of abstraction is lower then Employee Class's. It devastates an abstraction.
To persue the convenience of reading not the convenience of writing codes.
It takes more time to read codes than to write codes
If you make a program through interfaces, It's gonna break capsulation. then It's gonna break abstraction as well.
-> make a program through priavate functions.
To be careful the class including more than 7 data members.
If there is a class which has more than 7 data members, you consider whether u should devide the class.
To design for inheritance. If not, make it impossible to inherit. : C++ -> non-virtual, Java -> final
To be doubt if there is base class which has a derived class. Make it simple to a class.
If there is a class which has functhion doing nothing, u should change the origin.
ex) Cat Class and Scratch() <- ScratchlessCat and Scratch()- doing nothing. : It would be a problem.
Cat Class includes Claws Class. It's better.
To make data private instead of protected. - Joshua Bloch said "Inheritance break capsulation"
The case of using switch ~ case , U should use it when cases are about totally different classes or actions.
It's an example that seems to be changed to polymorphism.
-
switch( shape.type ){
-
case Shape_Circle:
-
shape_DrawCircle();
-
break;
-
case Shape_Square:
-
shape.DrawSquare();
-
break;
-
...
-
}
It's an example that seems unable to be changed to polymorphism.
-
switch( ui.Command() )
-
{
-
case Command_OpenFile:
-
OpenFile();
-
break;
-
case Command_Print:
-
print();
-
break;
-
....
-
}
instance => which has an object.
If there is a class without members and with only actions, u should avoid to make that class.
In JAVA, All rutines are possible to override and to prevent inheritance to use a final routine.
In C++, basically it's impossible to override. u should 선언 virtual for inheritance.
'책 정리 > Code Complete 2nd' 카테고리의 다른 글
[Code Complete 2nd/e] Words - 1 (0) | 2009.03.18 |
---|---|
Code Complete - Eng Version Doc (0) | 2009.03.18 |
Part 2 - Chapter 8 Defensive Programming (0) | 2009.03.09 |