Here is a nice one:Code:if(TRUE == SomeFunctionReturningBOOL())
{
//... do something
}
Code:if(<some_error_condition>)
{
AfxMessageBox(strError.LoadString(IDS_SOME_ERROR_MESSAGE));
}
Printable View
Here is a nice one:Code:if(TRUE == SomeFunctionReturningBOOL())
{
//... do something
}
Code:if(<some_error_condition>)
{
AfxMessageBox(strError.LoadString(IDS_SOME_ERROR_MESSAGE));
}
General Database programming:
Begin transaction.
Do some work
if(error)
{
Message box with error description (or not:eek: )
rollback transaction -(and all other users wait for user to click "OK", but user goes to administrator for help :D )
}
else commit transaction
Ones I hate are inconsistency:
iChargingFreq = GetPaymentFreq();
where the payment frequency may be totally different to the charging frequency yet the variable names used makes the code almost impossible to understand.
not technically an "error", but I wouldn't pass it in any code review.
int *pArray= new int [x];
delete pArray;:D
Is somebody curious to push <Yes> ?
I hope you enjoy this one. Huge but it works! :cool:
Problem is, it's difficult to maintain. :(
SELECT a.num_lev_modu,
a.co_crc_modu,
A.co_modu,
A.na_cmp_modu,
A.na_abr_modu,
A.num_CR, A.co_depc_adm,
A.co_area_acd,
A.co_dptm_acd,
A.co_lect_prin,
A.co_sect,
A.qt_vact_disp,
A.num_grp_sect,
SUBSTR( VALUE(D.na_last_pers,' ')|| ' ' || VALUE(D.na_mid_pers,' ')|| ' ' ||
VALUE(D.na_first_pers,' '),1,30),
a.fg_impr_ttb,
a.fg_stat_sect,
a.fg_stat_prog_sect,
a.qt_stu_regi,
a.fg_lock_regi,
a.fh_last_regi,
a.qt_vact,
A.fg_vact_sect,
A.fg_ctl_vact_sect,
CAPC_ambi
FROM (
SELECT A.num_lev_modu,
A.co_crc_modu,
B.co_modu,
B.na_cmp_modu,
B.na_abr_modu,
B.num_CR,
B.co_actv_lect_prin,
B.co_area_acd,
B.co_dptm_acd,
C.AA_semt,
C.num_semt,
C.num_sec_semt,
C.co_depc_adm_sect as co_depc_adm,
C.co_lect_prin,
N.co_sect,
C.fg_regi_grp_sect,
C.fg_grp_sect,
C.fg_stat_prog_sect,
C.fg_lock_regi,
C.fg_vact_sect,
C.fg_ctl_vact_sect,
0 AS num_grp_sect,
D.qt_vact,
D.qt_stu_regi,
(D.qt_vact - D.qt_stu_regi) AS qt_vact_disp,
C.fg_impr_ttb,
C.fg_stat_sect,
C.fh_last_regi,
(Select MIN(w.qt_capc_pers) AS qt_max_pers
from db2host.activity_lect x,
db2host.type_activ_lect y,
db2host.timetable_activ_lect z,
db2host.room w
where x.co_actv_lect = y.co_actv_lect and
x.aa_semt = C.aa_semt and
x.num_semt = C.num_semt and
x.co_modu = C.co_modu and
x.co_sect = C.co_sect and
y.co_grp_actv_lect = 1 and
y.co_Sgrp_actv_lect = 1 and
x.num_actv_lect = z.num_actv_lect and
(z.num_grp_sect is null or
z.num_grp_sect = 0) and
z.date_sta_vig_ttb <= date('1997-09-01') and
z.date_end_vig_ttb >= date('1999-08-31') and
w.num_ambi = z.num_ambi) AS CAPC_ambi
FROM db2host.plan A
inner join db2host.module B
on a.co_modu = b.co_modu AND
a.co_espc = 'CS76000' and
a.num_lev_modu >= 1 and
a.num_semt_end_VIG is NULL
INNER JOIN db2host.program B1
ON A.co_espc = B1.co_espc
inner join db2host.section N
ON A.co_modu = N.co_modu AND
N.AA_semt = 2005 AND
N.num_semt = 1 AND
N.num_sec_semt = 1 AND
N.co_sect/100 = A.num_lev_modu AND
N.co_modu_ref IS NOT nuLL AND
N.co_sect_ref IS NOT nuLL
inner join db2host.section C
ON N.co_modu_ref = C.co_modu AND
N.AA_semt = C.AA_semt AND
N.num_semt = C.num_semt AND
N.num_sec_semt = C.num_sec_semt AND
N.co_sect_ref = C.co_sect AND
C.fg_sect_adms = '0' AND
C.fg_ctl_vact_sect = '1' AND
C.fg_stat_sect = '0' and
C.fg_stat_prog_sect = '1'
INNER JOIN db2host.Department C1
ON C1.co_depc = C.co_depc_adm_sect AND
B1.co_depc = C1.co_depc_sup
INNER JOIN db2host.places_section D
ON C.AA_semt = D.AA_semt AND
C.num_semt = D.num_semt AND
C.num_sec_semt = D.num_sec_semt AND
C.co_modu = D.co_modu AND
C.co_sect = D.co_sect AND
C.co_modu = D.co_modu AND
D.co_espc = A.co_espc
UNION
SELECT A.num_lev_modu,
A.co_crc_modu,
B.co_modu,
B.na_cmp_modu,
B.na_abr_modu,
B.num_cr,
B.co_actv_lect_prin,
B.co_area_acd,
B.co_dptm_acd,
C.AA_semt,
C.num_semt,
C.num_sec_semt,
C.co_depc_adm_sect AS co_depc_adm,
(Select max(w.co_lect)
from db2host.activity_lect x,
db2host.timetable_activ_lect y,
db2host.timetable_labor_lect z,
db2host.labor_lect_assig w
where x.aa_semt = c.aa_semt and
x.num_semt = c.num_semt and
x.co_modu = c.co_modu and
x.co_sect = c.co_sect and
y.num_actv_lect = x.num_actv_lect and
y.num_grp_sect = c2.num_grp_sect and
y.date_sta_vig_ttb <= date('1997-09-01') and
y.date_end_vig_ttb >= date('1999-08-31') and
z.num_ttb = y.num_ttb and
z.date_sta_vig_ttb <= date('1997-09-01') and
z.date_end_vig_ttb >= date('1999-08-31') and
w.num_lbor = z.num_lbor) as co_lect_prin,
N.co_sect,
C.fg_regi_grp_sect,
C.fg_grp_sect,
C.fg_stat_prog_sect,
C.fg_lock_regi,
C.fg_vact_sect,
C.fg_ctl_vact_sect,
C2.num_grp_sect,
C2.qt_vact,
C2.qt_stu_regi,
(C2.qt_vact - C2.qt_stu_regi) AS qt_vact_disp,
C2.fg_impr_ttb,
C2.fg_stat_grp_sect AS fg_stat_sect,
C2.fh_last_regi,
(Select MIN(w.qt_capc_pers) AS qt_max_pers
from db2host.activity_lect x,
db2host.type_activ_lect y,
db2host.timetable_activ_lect z,
db2host.room w
where x.co_actv_lect = y.co_actv_lect and
x.aa_semt = C.aa_semt and
x.num_semt = C.num_semt and
x.co_modu = C.co_modu and
x.co_sect = C.co_sect and
y.co_grp_actv_lect = 1 and
y.co_Sgrp_actv_lect = 1 and
x.num_actv_lect = z.num_actv_lect and
z.num_grp_sect = C2.num_grp_sect AND
z.date_sta_vig_ttb <= date('1997-09-01') and
z.date_end_vig_ttb >= date('1999-08-31') and
w.num_ambi = z.num_ambi) AS CAPC_ambi
FROM db2host.plan A
inner join db2host.module B
on A.co_modu = B.co_modu AND
a.co_espc = 'CS76000' and
A.num_lev_modu >= 3 and
A.num_semt_end_VIG is NULL)
INNER JOIN db2host.program B1
ON A.co_espc = B1.co_espc
inner join db2host.section N
ON N.co_modu = A.co_modu AND
N.AA_semt = 2005 AND
N.num_semt = 1 AND
N.num_sec_semt = 1 AND
N.co_sect/100 = A.num_lev_modu AND
N.co_modu_ref IS NOT NULL AND
N.co_sect_ref IS NOT NULL
INNER JOIN db2host.group_section C2
ON C2.co_modu = N.co_modu_ref AND
C2.AA_semt = N.AA_semt AND
C2.num_semt = N.num_semt AND
C2.num_sec_semt = N.num_sec_semt AND
C2.co_sect = N.co_sect_ref AND
C2.fg_stat_grp_sect = '1'
inner join db2host.section C
ON C.co_modu = C2.co_modu AND
C.AA_semt = C2.AA_semt AND
C.num_semt = C2.num_semt AND
C.num_sec_semt = C2.num_sec_semt AND
C.co_sect = C2.co_sect AND
C.fg_stat_sect = '0' and
C.fg_stat_prog_sect = '1'
INNER JOIN db2host.department C1
ON C1.co_depc = C.co_depc_adm_sect AND
B1.co_depc = C1.co_depc_sup
) A
LEFT OUTER JOIN db2host.employee C
ON A.co_lect_prin = C.co_empl
LEFT OUTER JOIN db2host.persON D
ON C.co_pers = D.co_pers
ORDER BY a.num_lev_modu, A.co_modu, A.co_sect, A.num_grp_sect
Yeah, I remember such kind of queries generally made by some wise analysts using a visual tool. What's bad is that almost always if something goes wrong it's a developers' task to find out why.
THE EMPTY TABLE BUG
A wise programmer expects that a query returns at lest one row, so why wasting time to test it?
Well, must happen, usually at the client and the aplication creshes before a coherent prompt message.
No problem, if it's running under XP, you can tell the client to push "Send Error Report" (see attached).
Maybe MS can find a solution... :D :D
A fresh one
/yummy, yummy :DCode:void CFoo::Init(int x, int y)
{
if(!m_db.Open())
return;
// in some circumstances nice, good, appetitive garbage below
m_x = x;
m_y = y;
}
The one I really like:
Or the eternal:Code:if (bCondition && bOtherCondition) {
Dosomething();
if (!bCondition) {
// error message
}
}
Code:If Condition And c="a" Or c="b" Or c="c" Then
' Do something
End If
Please, can somebody give me a gun?!Code:namespace
{
BOOL LOOK_IN_TRACER = FALSE;
}
// ...
// ...
// ...
if(m_odtBegDate > m_odtEndDate)
{
ERROR_TRACE(_T("beginning date should be smaller than or equal to ending date"));
_ASSERTE(LOOK_IN_TRACER);
}
// ...
// ...
// ...
I suppose my major gripe is about completely pointless comments.
I see this kind of thing all the time, especially from people who shout about how great auto-documentation software is. Makes me laugh.
AlsoCode:// class which does the drawing
class DrawingClass
{
public:
// this method draws a circle
void DrawCircle();
}
Another of my pet hates is people typedef-ing STL classes. This makes the code exceptionally unreadable.Code:// this is the counter for the number of oranges
int nX = 0;
// why not just do :
int nOrangesCount = 0;
Of course all the standard ones stand : like 1000 line methods with huge blocks of commented out code in them.Code:// somewhere in a .h
typedef std::vector<int> INTVECTOR;
void MyFunction()
{
// what the heck is INTVECTOR ???
INTVECTOR vector;
}
Not using enums for constants as well. What the heck is '10276' when it's at home ? (or any other constant).
Man, I could go on forever.
Darwen.
(about Java code)
There is a "rule": when class grows more then (even more so) 2000 lines, you should cut the problem to smaller entities. Guess what? New class is created (say, Derived) subclassing original one (say, Base) and new methods just appear in Derived instead of Base, every now and then being accessed from Base using ((Derived)this).theNewMethod() conversion.
Class fields are evidently all public and are accessed and being changed (of course they are mutable) from everywhere. Variables in procedures are listed at the beginning of procedure, named by pattern:Code:Var var;
Var varr;
Var varrr;
Var var2;
Be my guest. :D ;) :thumb:Quote:
Originally Posted by darwen
My pet peeve is when a developer always throws the same exception from every method they write making it impossible to catch specific exceptions being thrown. Or worse, rethrowing a less informative exception in the place of a helpful exception.
And then I go to execute this method and get back a general exception that "Something went wrong". And then I have to guess what that "something" was...Code:public class Widget
{
public void ConnectToDatabase()
{
try
{
odbc.Open()
ocbc.ExceuteQuery()
/* Do a bunch of other stuff */
odbc.Close()
}
catch ( OdbcException ex )
{
throw new Exception( "Something went wrong" );
// -- OR --
MessageBox.Show( "Something went wrong" );
}
}
}
I can't tell you how many times I've come across this or something like it