SlideShare a Scribd company logo
1 of 3
Download to read offline
Knee-deep in C++ s... code
Author: Andrey Karpov

Date: 01.03.2011

Perhaps many of you know the site govnokod.ru. If not, I recommend those of you who think of
themselves as programmers to visit it. Good mood is guaranteed! This is how the site describes itself:

Found or squeezed out code you can't call fine, code you can't help laughing at? Do not rush at deleting
or refactoring it - post it at govnokod.ru, let's laugh together!

I, due to my occupation, spend much time on meditation upon very diverse C++ code. So, as they say, I
have just enough of that stuff stored up. I can't carry this anymore inside me. Excuse me, but I will share
it with you too.

Here you are the Top 10 of the "best" code fragments I've collected recently. These samples have one
significant difference from those collected at the site "Govnokod.ru". While many of those samples are
taken from students' works and private little-known projects, my samples are taken from reputable
sources. These are well known open-source applications and libraries. Everyone have been using these
projects and libraries regularly for many years. I won't name them since I believe it's unethical: one
especially beautiful code fragment you might encounter in some project doesn't mean the bad quality of
the whole project.


10. Fair election of candidates from parties TRUE and FALSE.
m_bTypeED = ( nCmd == nCmd ) ? TRUE : FALSE;


9. Oh Lord, let the database always open - what is all that "frobnitz" for?
wstring myDBFName;

...

printf("Cannot open database %s",myDBFName);


8. You'd better not do such things with Ctrl-V.
fhead[11] = '0';

fhead[12] = '0';

fhead[13] = '0';

fhead[13] = '0';
7. A nice and detailed comment is a good thing! But correct code is
better.
/** Deletes all previous field specifiers.

    * This should be used when dealing with clients that

    * send multiple NEP_PACKET_SPEC messages, so only the last

    * PacketSpec is taken into account. */

int NEPContext::resetClientFieldSpecs() {

    this->fspecs.empty();

    return OP_SUCCESS;

} /* End of resetClientFieldSpecs() */


6. Simple and smart.
flag = true;

flag = false;

// flag is not used further anywhere


5. What if check fails at the first time...
if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)||

    (mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted))

Note. gameon and gamestarted are common variables of the bool type.


4. Original sin of Basic.
t.printf("%10.5f, %10.5f, %10.5f,n%10.5f, %10.5f,

              %10.5f,n%10.5f, %10.5f, %10.5f)",

            m[0, 0], m[0, 1], m[0, 2],

            m[1, 0], m[1, 1], m[1, 2],

            m[2, 0], m[2, 1], m[2, 2]);


3. A loop to conceive the Tao.
for (i = 0; i < num_tbl; i++) {

    *tbl++;

}
2. Well, where will this file go after all? That'll do.
FILE *fp;

if (! (fp = fopen(filename, "wb")) == -1) {

    perror("opening image file failed");

    exit(1);

}

Note. This condition is always false thanks to two errors. Come on, find them, you pursuer of truth!


1. The first place goes to switch operator.
switch(LOWORD(wParam))

    {

        case (IDOK || IDCANCEL):

         EndDialog(hDlg,TRUE);

         return(TRUE);

         break;

    }


Conclusions
Well, there is one conclusion as always: he who makes no mistakes, makes nothing. No developer, even
a skillful one, is secure from even silliest errors.

More Related Content

What's hot

Block introduce
Block introduceBlock introduce
Block introducebang590
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! Jack Franklin
 
Koha Cronjobs
Koha CronjobsKoha Cronjobs
Koha Cronjobsohiocore
 
block introduce
block introduceblock introduce
block introducebang590
 
Compiladoresemulador
CompiladoresemuladorCompiladoresemulador
CompiladoresemuladorDavid Caicedo
 
Instalación de emu8086
Instalación de emu8086Instalación de emu8086
Instalación de emu8086Alex Toapanta
 
Lesson 2 starting output
Lesson 2 starting outputLesson 2 starting output
Lesson 2 starting outputWayneJones104
 
Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086Santy Bolo
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086Jhon Alexito
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)jahanullah
 
Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsLuka Zakrajšek
 
UTAU DLL voicebank and ulauncher
UTAU DLL voicebank and ulauncherUTAU DLL voicebank and ulauncher
UTAU DLL voicebank and ulauncherhunyosi
 

What's hot (20)

Block introduce
Block introduceBlock introduce
Block introduce
 
CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better! CoffeeScript: JavaScript, but Better!
CoffeeScript: JavaScript, but Better!
 
Koha Cronjobs
Koha CronjobsKoha Cronjobs
Koha Cronjobs
 
block introduce
block introduceblock introduce
block introduce
 
Compiladoresemulador
CompiladoresemuladorCompiladoresemulador
Compiladoresemulador
 
Instalación de emu8086
Instalación de emu8086Instalación de emu8086
Instalación de emu8086
 
Lesson 2 starting output
Lesson 2 starting outputLesson 2 starting output
Lesson 2 starting output
 
Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086
 
Telegram bots
Telegram botsTelegram bots
Telegram bots
 
Looping in C
Looping in CLooping in C
Looping in C
 
Design problem
Design problemDesign problem
Design problem
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Loops
LoopsLoops
Loops
 
Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math ops
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
Test Fest 2009
Test Fest 2009Test Fest 2009
Test Fest 2009
 
For Loop
For LoopFor Loop
For Loop
 
UTAU DLL voicebank and ulauncher
UTAU DLL voicebank and ulauncherUTAU DLL voicebank and ulauncher
UTAU DLL voicebank and ulauncher
 

Viewers also liked

как загрузить файл на форум
как загрузить файл на форумкак загрузить файл на форум
как загрузить файл на форумskatelal
 
Millennium city park, kaifeng (開封清明上河園)
Millennium city park, kaifeng (開封清明上河園)Millennium city park, kaifeng (開封清明上河園)
Millennium city park, kaifeng (開封清明上河園)Chung Yen Chang
 
Zagreb 2013 FER
Zagreb 2013 FER Zagreb 2013 FER
Zagreb 2013 FER Igor Brusic
 
Security Scanner Design am Beispiel von httprecon
Security Scanner Design am Beispiel von httpreconSecurity Scanner Design am Beispiel von httprecon
Security Scanner Design am Beispiel von httpreconMarc Ruef
 
Art of eXperiential Learning
Art of eXperiential LearningArt of eXperiential Learning
Art of eXperiential Learninganandxp
 
Running Technique and Gear
Running Technique and GearRunning Technique and Gear
Running Technique and Gearnobody020
 
Estrutura - submissão de artigo para revista
Estrutura  - submissão de artigo para revistaEstrutura  - submissão de artigo para revista
Estrutura - submissão de artigo para revistaitaboray78
 
FIGURINES. Color
FIGURINES. ColorFIGURINES. Color
FIGURINES. ColorIndumental
 
Schulden und Vermögen in Österreich und international
Schulden und Vermögen in Österreich und internationalSchulden und Vermögen in Österreich und international
Schulden und Vermögen in Österreich und internationalMichael Girkinger
 
Samsung Shows How to Bring IoT to Life at IFA 2015 v. Patents
Samsung Shows How to Bring IoT to Life at IFA 2015 v. PatentsSamsung Shows How to Bring IoT to Life at IFA 2015 v. Patents
Samsung Shows How to Bring IoT to Life at IFA 2015 v. PatentsAlex G. Lee, Ph.D. Esq. CLP
 
Storyboard Aa
Storyboard AaStoryboard Aa
Storyboard Aatariq.s
 

Viewers also liked (20)

как загрузить файл на форум
как загрузить файл на форумкак загрузить файл на форум
как загрузить файл на форум
 
Millennium city park, kaifeng (開封清明上河園)
Millennium city park, kaifeng (開封清明上河園)Millennium city park, kaifeng (開封清明上河園)
Millennium city park, kaifeng (開封清明上河園)
 
Zagreb 2013 FER
Zagreb 2013 FER Zagreb 2013 FER
Zagreb 2013 FER
 
Security Scanner Design am Beispiel von httprecon
Security Scanner Design am Beispiel von httpreconSecurity Scanner Design am Beispiel von httprecon
Security Scanner Design am Beispiel von httprecon
 
Art of eXperiential Learning
Art of eXperiential LearningArt of eXperiential Learning
Art of eXperiential Learning
 
Running Technique and Gear
Running Technique and GearRunning Technique and Gear
Running Technique and Gear
 
Moș Crăciun
Moș CrăciunMoș Crăciun
Moș Crăciun
 
Estrutura - submissão de artigo para revista
Estrutura  - submissão de artigo para revistaEstrutura  - submissão de artigo para revista
Estrutura - submissão de artigo para revista
 
Fentect liminar
Fentect liminarFentect liminar
Fentect liminar
 
Lo mejor en electrocomesticos
Lo mejor en electrocomesticosLo mejor en electrocomesticos
Lo mejor en electrocomesticos
 
Bo 23 01-2012-3
Bo 23 01-2012-3Bo 23 01-2012-3
Bo 23 01-2012-3
 
Anti cut protections
Anti cut protectionsAnti cut protections
Anti cut protections
 
Teenosaurus
TeenosaurusTeenosaurus
Teenosaurus
 
Team phsk part3
Team phsk part3Team phsk part3
Team phsk part3
 
Russia e commerce update june 2013
Russia e commerce update june 2013Russia e commerce update june 2013
Russia e commerce update june 2013
 
FIGURINES. Color
FIGURINES. ColorFIGURINES. Color
FIGURINES. Color
 
Schulden und Vermögen in Österreich und international
Schulden und Vermögen in Österreich und internationalSchulden und Vermögen in Österreich und international
Schulden und Vermögen in Österreich und international
 
Samsung Shows How to Bring IoT to Life at IFA 2015 v. Patents
Samsung Shows How to Bring IoT to Life at IFA 2015 v. PatentsSamsung Shows How to Bring IoT to Life at IFA 2015 v. Patents
Samsung Shows How to Bring IoT to Life at IFA 2015 v. Patents
 
Big deciamal
Big deciamalBig deciamal
Big deciamal
 
Storyboard Aa
Storyboard AaStoryboard Aa
Storyboard Aa
 

Similar to Knee-deep in C++ s... code

Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" DependenciesAnalyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" DependenciesPVS-Studio
 
Analyzing the Blender project with PVS-Studio
Analyzing the Blender project with PVS-StudioAnalyzing the Blender project with PVS-Studio
Analyzing the Blender project with PVS-StudioPVS-Studio
 
Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1) Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1) Andrey Karpov
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingAndrey Karpov
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingPVS-Studio
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youAndrey Karpov
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Andrey Karpov
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioAndrey Karpov
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedAndrey Karpov
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codeAndrey Karpov
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project AnalyzedPVS-Studio
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?PVS-Studio
 
Why Students Need the CppCat Code Analyzer
Why Students Need the CppCat Code AnalyzerWhy Students Need the CppCat Code Analyzer
Why Students Need the CppCat Code AnalyzerPVS-Studio
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodeA Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodePVS-Studio
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer ReviewAndrey Karpov
 

Similar to Knee-deep in C++ s... code (20)

Grounded Pointers
Grounded PointersGrounded Pointers
Grounded Pointers
 
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" DependenciesAnalyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
 
Analyzing the Blender project with PVS-Studio
Analyzing the Blender project with PVS-StudioAnalyzing the Blender project with PVS-Studio
Analyzing the Blender project with PVS-Studio
 
Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1) Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and Everything
 
The Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and EverythingThe Ultimate Question of Programming, Refactoring, and Everything
The Ultimate Question of Programming, Refactoring, and Everything
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
 
Errors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not usedErrors that static code analysis does not find because it is not used
Errors that static code analysis does not find because it is not used
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
PVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's codePVS-Studio: analyzing ReactOS's code
PVS-Studio: analyzing ReactOS's code
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project Analyzed
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?
 
Checking VirtualDub
Checking VirtualDubChecking VirtualDub
Checking VirtualDub
 
Why Students Need the CppCat Code Analyzer
Why Students Need the CppCat Code AnalyzerWhy Students Need the CppCat Code Analyzer
Why Students Need the CppCat Code Analyzer
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source CodeA Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
A Unicorn Seeking Extraterrestrial Life: Analyzing SETI@home's Source Code
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer Review
 

Recently uploaded

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

Knee-deep in C++ s... code

  • 1. Knee-deep in C++ s... code Author: Andrey Karpov Date: 01.03.2011 Perhaps many of you know the site govnokod.ru. If not, I recommend those of you who think of themselves as programmers to visit it. Good mood is guaranteed! This is how the site describes itself: Found or squeezed out code you can't call fine, code you can't help laughing at? Do not rush at deleting or refactoring it - post it at govnokod.ru, let's laugh together! I, due to my occupation, spend much time on meditation upon very diverse C++ code. So, as they say, I have just enough of that stuff stored up. I can't carry this anymore inside me. Excuse me, but I will share it with you too. Here you are the Top 10 of the "best" code fragments I've collected recently. These samples have one significant difference from those collected at the site "Govnokod.ru". While many of those samples are taken from students' works and private little-known projects, my samples are taken from reputable sources. These are well known open-source applications and libraries. Everyone have been using these projects and libraries regularly for many years. I won't name them since I believe it's unethical: one especially beautiful code fragment you might encounter in some project doesn't mean the bad quality of the whole project. 10. Fair election of candidates from parties TRUE and FALSE. m_bTypeED = ( nCmd == nCmd ) ? TRUE : FALSE; 9. Oh Lord, let the database always open - what is all that "frobnitz" for? wstring myDBFName; ... printf("Cannot open database %s",myDBFName); 8. You'd better not do such things with Ctrl-V. fhead[11] = '0'; fhead[12] = '0'; fhead[13] = '0'; fhead[13] = '0';
  • 2. 7. A nice and detailed comment is a good thing! But correct code is better. /** Deletes all previous field specifiers. * This should be used when dealing with clients that * send multiple NEP_PACKET_SPEC messages, so only the last * PacketSpec is taken into account. */ int NEPContext::resetClientFieldSpecs() { this->fspecs.empty(); return OP_SUCCESS; } /* End of resetClientFieldSpecs() */ 6. Simple and smart. flag = true; flag = false; // flag is not used further anywhere 5. What if check fails at the first time... if(freeze||winfreeze||(mainmenu&&gameon)||(!gameon&&gamestarted)|| (mainmenu&&gameon)||(!gameon&&gamestarted)||(!gameon&&gamestarted)) Note. gameon and gamestarted are common variables of the bool type. 4. Original sin of Basic. t.printf("%10.5f, %10.5f, %10.5f,n%10.5f, %10.5f, %10.5f,n%10.5f, %10.5f, %10.5f)", m[0, 0], m[0, 1], m[0, 2], m[1, 0], m[1, 1], m[1, 2], m[2, 0], m[2, 1], m[2, 2]); 3. A loop to conceive the Tao. for (i = 0; i < num_tbl; i++) { *tbl++; }
  • 3. 2. Well, where will this file go after all? That'll do. FILE *fp; if (! (fp = fopen(filename, "wb")) == -1) { perror("opening image file failed"); exit(1); } Note. This condition is always false thanks to two errors. Come on, find them, you pursuer of truth! 1. The first place goes to switch operator. switch(LOWORD(wParam)) { case (IDOK || IDCANCEL): EndDialog(hDlg,TRUE); return(TRUE); break; } Conclusions Well, there is one conclusion as always: he who makes no mistakes, makes nothing. No developer, even a skillful one, is secure from even silliest errors.