Click here to Skip to main content
11,572,389 members (37,096 online)

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: for(int i=0; i<size; i++) Pin
Antonino Porcino1-May-13 5:03
memberAntonino Porcino1-May-13 5:03 
GeneralRe: for(int i=0; i<size; i++) Pin
RafagaX1-May-13 6:38
memberRafagaX1-May-13 6:38 
GeneralRe: for(int i=0; i<size; i++) Pin
Carlosian2-May-13 4:36
memberCarlosian2-May-13 4:36 
GeneralRe: for(int i=0; i<size; i++) Pin
Member 100271053-May-13 6:15
memberMember 100271053-May-13 6:15 
GeneralRe: for(int i=0; i<size; i++) Pin
robocodeboy5-May-13 23:27
memberrobocodeboy5-May-13 23:27 
GeneralRe: for(int i=0; i<size; i++) Pin
Nicolas Dorier4-May-13 21:37
memberNicolas Dorier4-May-13 21:37 
GeneralRe: for(int i=0; i<size; i++) Pin
peterchen6-May-13 2:58
memberpeterchen6-May-13 2:58 
GeneralRe: for(int i=0; i<size; i++) Pin
DanielSheets6-May-13 7:12
memberDanielSheets6-May-13 7:12 
GeneralRe: for(int i=0; i<size; i++) Pin
DerekTP1238-May-13 0:26
memberDerekTP1238-May-13 0:26 
Generalwhile(life!=death) Pin
Bikash Prakash Dash11-May-13 5:03
memberBikash Prakash Dash11-May-13 5:03 
GeneralRe: for(int i=0; i<size; i++) Pin
PeterTheSwede19-May-13 23:58
memberPeterTheSwede19-May-13 23:58 
GeneralRe: for(int i=0; i<size; i++) Pin
John Hunley29-May-13 8:46
memberJohn Hunley29-May-13 8:46 
GeneralRe: for(int i=0; i<size; i++) Pin
BCantor31-May-13 9:54
memberBCantor31-May-13 9:54 
GeneralInteresting Observation Pin
virang_2129-Apr-13 14:45
membervirang_2129-Apr-13 14:45 
I was looking at one old SQL stored proc and found this strange behaviour.

 
DECLARE @Scrap_Qty int
DECLARE @FilledQty int
SET @Scrap_Qty=10 --Change this to 1 and it still run
SET @FilledQty = 2
 
BEGIN
 
IF @Scrap_Qty  > @FilledQty
 declare @currDate varchar(10)   
 Set @currDate= Convert(VARCHAR(10),GetDate(),103)  
 PRINT @currDate
 
END  
 

Look at the if condition .. it does not have BEGIN..END... To make thing interesting weather if condition is true or false you will get the output for parameter @currDate

If I add PRINT @Scrap_Qty right after IF and run it again it will only print value for @Scrap_Qty if condition is true. Which leads to question why sql is not complaining about undeclared variable if @Scrap_Qty is less than @FilledQty ?

I would have assumed if condition without BEGIN .. END block will behave like a normal one line to execute if condition is true which in above block is declaration of @currDate variable.

DECLARE @Scrap_Qty int
DECLARE @FilledQty int
SET @Scrap_Qty=10 --Change this to 1 and it won't output @Scrap_Qty
SET @FilledQty = 2
 
BEGIN
 
IF @Scrap_Qty  > @FilledQty
	PRINT @Scrap_Qty
 declare @currDate varchar(10)   
 Set @currDate= Convert(VARCHAR(10),GetDate(),103)  
 PRINT @currDate
 
END  
Zen and the art of software maintenance : rm -rf *

Math is like love : a simple idea but it can get complicated.

GeneralRe: Interesting Observation Pin
Pablo Aliskevicius29-Apr-13 19:47
memberPablo Aliskevicius29-Apr-13 19:47 
GeneralRe: Interesting Observation Pin
agolddog1-May-13 3:42
memberagolddog1-May-13 3:42 
GeneralRe: Interesting Observation Pin
Raja Sekhar S5-Jun-13 21:14
professionalRaja Sekhar S5-Jun-13 21:14 
GeneralRe: Interesting Observation Pin
Pablo Aliskevicius5-Jun-13 21:21
memberPablo Aliskevicius5-Jun-13 21:21 
GeneralRe: Interesting Observation Pin
Raja Sekhar S5-Jun-13 22:05
professionalRaja Sekhar S5-Jun-13 22:05 
GeneralRe: Interesting Observation Pin
Pablo Aliskevicius5-Jun-13 23:31
memberPablo Aliskevicius5-Jun-13 23:31 
GeneralRe: Interesting Observation Pin
Raja Sekhar S5-Jun-13 23:39
professionalRaja Sekhar S5-Jun-13 23:39 
GeneralNot 'Clap' but 'CLAP', dammit. Pin
Brady Kelly24-Apr-13 22:36
memberBrady Kelly24-Apr-13 22:36 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
dusty_dex24-Apr-13 23:19
memberdusty_dex24-Apr-13 23:19 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
Brady Kelly24-Apr-13 23:33
memberBrady Kelly24-Apr-13 23:33 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
H.Brydon25-Apr-13 14:59
memberH.Brydon25-Apr-13 14:59 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
Brisingr Aerowing25-Apr-13 1:16
professionalBrisingr Aerowing25-Apr-13 1:16 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
Brady Kelly25-Apr-13 2:56
memberBrady Kelly25-Apr-13 2:56 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
hvanzyll26-Apr-13 5:26
memberhvanzyll26-Apr-13 5:26 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pin
Rob Grainger1-May-13 3:23
memberRob Grainger1-May-13 3:23 
GeneralProduction code adds a BCC to email account of developer Pin
0bx24-Apr-13 5:48
member0bx24-Apr-13 5:48 
AnswerRe: Production code adds a BCC to email account of developer Pin
AspDotNetDev24-Apr-13 5:54
protectorAspDotNetDev24-Apr-13 5:54 
GeneralRe: Production code adds a BCC to email account of developer Pin
CIDev25-Apr-13 9:17
memberCIDev25-Apr-13 9:17 
GeneralRe: Production code adds a BCC to email account of developer Pin
AspDotNetDev25-Apr-13 9:20
protectorAspDotNetDev25-Apr-13 9:20 
GeneralRe: Production code adds a BCC to email account of developer Pin
agolddog26-Apr-13 3:41
memberagolddog26-Apr-13 3:41 
GeneralRe: Production code adds a BCC to email account of developer Pin
Bernhard Hiller25-Apr-13 3:54
professionalBernhard Hiller25-Apr-13 3:54 
GeneralRe: Production code adds a BCC to email account of developer Pin
RafagaX26-Apr-13 4:42
memberRafagaX26-Apr-13 4:42 
GeneralNested if-else statements... Pin
ProgramFOX23-Apr-13 7:21
member ProgramFOX23-Apr-13 7:21 
GeneralRe: Nested if-else statements... Pin
GeekBond 23-Apr-13 7:49
member GeekBond 23-Apr-13 7:49 
GeneralRe: Nested if-else statements... Pin
OriginalGriff23-Apr-13 8:12
mvpOriginalGriff23-Apr-13 8:12 
GeneralRe: Nested if-else statements... Pin
s_mon23-Apr-13 9:48
members_mon23-Apr-13 9:48 
GeneralRe: Nested if-else statements... Pin
Monaco.Bavarian23-Apr-13 19:54
memberMonaco.Bavarian23-Apr-13 19:54 
GeneralRe: Nested if-else statements... Pin
Marius ten Napel24-Apr-13 1:51
memberMarius ten Napel24-Apr-13 1:51 
GeneralRe: Nested if-else statements... Pin
ryanb3124-Apr-13 2:10
memberryanb3124-Apr-13 2:10 
GeneralRe: Nested if-else statements... Pin
Marius ten Napel24-Apr-13 2:36
memberMarius ten Napel24-Apr-13 2:36 
GeneralRe: Nested if-else statements... Pin
dusty_dex24-Apr-13 3:43
memberdusty_dex24-Apr-13 3:43 
GeneralRe: Nested if-else statements... Pin
NAANsoft24-Apr-13 2:44
memberNAANsoft24-Apr-13 2:44 
GeneralRe: Nested if-else statements... Pin
Lee Chetwynd24-Apr-13 5:07
memberLee Chetwynd24-Apr-13 5:07 
GeneralRe: Nested if-else statements... Pin
RafagaX24-Apr-13 5:41
memberRafagaX24-Apr-13 5:41 
GeneralRe: Nested if-else statements... Pin
tumbledDown2earth29-Apr-13 20:32
membertumbledDown2earth29-Apr-13 20:32 
GeneralRe: Nested if-else statements... Pin
fulloflove2-May-13 17:19
memberfulloflove2-May-13 17:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 2 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid