pouët.net

Go to bottom

the unnecessary dumbhead-coding thread

category: general [glöplog]
i used plenty of "nop" loops back in the 386 days, to allow for VGA cards (or actually any other "laggy" hardware) to synch up with register changes... there were probably better and more compatible ways, but nops where alright :)

... plus, i was never good at assembler :)
added on the 2009-02-15 17:29:15 by Jcl Jcl
Yes, NOPs on the CPC. To synchronize raster effects and any thing that has to wait a bit for the vertical retrace to reach a point and then do it's work. I never actually understood how NOPs would work on PC because they don't have a fixed speed to be sure that you need X NOPs to reach that point. But PCs have wait for horizontal sync and so it could be easy to do the same tricks per raster line. C64s also have irq line interrupts (which CPC the plain not the plus lacks) but I think at some occasions coders still need to use NOPs for some synchronizations.
added on the 2009-02-15 17:38:20 by Optimus Optimus
Although instead of NOPs you could use any other opcode provided it spends as few cycles as possible and does something that doesn't interfere with your registers or code (like MOV AX,AX or LD A,A or anything). But NOP is simply more simple and elegant.
added on the 2009-02-15 17:40:03 by Optimus Optimus
skrebbel said something to me at BP08 that i never thought about my nick
int a = b << 0;
added on the 2009-02-15 17:48:45 by zeroshift zeroshift
Code:fld dword [si-12] ; s fsincos ; sin(s) cos(s) fld1 ; 1 s sin(s) cos(s) fdivr dword [si-12] fsincos ; sin(s/2) cos(s/2) cos(s) sin(s)

If that's what he wanted, then he just forgot a FADD, so it wasn't that big of a mess :P Well, except that what he would've gotten in that case is sin(s/2) cos(s/2) sin(s) cos(s) which doesn't match the last comment anyway :P
added on the 2009-02-15 18:19:58 by mic mic
I see variations of this more often than I want to:
Code:if (foo == true) { result = true; } else { result = false; } return result;
added on the 2009-02-15 18:55:21 by Joghurt Joghurt
Joghurt: Yes, that's one great piece of code! And in addition to that masterpiece you can see lots and lots of if-else-nesting inside those functions very often.
added on the 2009-02-15 19:36:47 by hcdlt hcdlt
skrebbel, well, on x86 and i think on 6510 too, nop is just another name for some other instruction which would exist anyway but not do anything ('xchg ax,ax' on x86). On 6510 it is well known that the engineers were trying to design the simplest possible circuits because of time and cost constrains; that's why all the interesting undocumented instructions exist, they just fell out of the circuit design.

Now, nop is not really useless either, on x86 you can use it for padding, for example you want a short loop to start at some aligned address because of how the cache works (well, take anything i say about the cache with a grain of salt, and imagine that we are in the 90s, but something like that). On c64 it is often used for timing cycle-exact stuff (i think).
added on the 2009-02-15 19:38:16 by blala blala
Joghurt: I usually do that kind of constructs when there -might- be other stuff affecting the results which I hadn't thought of at the time of writing it.

They tend to slip into production code more often than not though :-)

This is production code:
Code:if (e.FieldName == "esUsuario" && (e.Value ?? String.Empty).ToString() == String.Empty) e.Value = true; else e.Value = false;

Ah, well :D
added on the 2009-02-15 20:46:40 by Jcl Jcl
"nop" is esperanto for "inject code here"
added on the 2009-02-15 20:50:27 by Gargaj Gargaj
Quote:
I usually do that kind of constructs when there -might- be other stuff affecting the results which I hadn't thought of at the time of writing it.
But even then you don't check if a boolean == true, you just do if(foo), or do you? ;-)
added on the 2009-02-15 22:03:07 by Joghurt Joghurt
Joghurt: on C++, definitely... on c# (which I have been mostly coding since 2003), "depends"... I tend to use a lot of boxing on objects, and nullables, which just don't work with that syntax (even if they are bool)... so I sometimes just write == true (or the more correct, "object.Equals(mybool, true)") and don't even think which type it is :)
added on the 2009-02-15 22:17:27 by Jcl Jcl
Joghurt: the fact is that, I should (and do many times) put a HACK, or TODO note there and "fix it" for production code... but the reality is that most of those "to-do's" slip to production (generally because of tight deadlines).
added on the 2009-02-15 22:19:09 by Jcl Jcl
A little gem I just found (this is production code, on a commercial application), by myself:

Code: PropertyInfo pi = t.GetProperty("IdHorarioTurno" + i.ToString()); int hT = ((int?)pi.GetValue(ph, null)) ?? 0; rhHorarioTurno ht = d.rhHorarioTurnos.SingleOrDefault(p => p.IdHorarioTurno == hT); if (ht != null) { nombreHorario = ht.Nombre; switch (diaSemana) { case 1: horasCortesia = ht.horasCortesiaLunes ?? 0; return ht.HorarioLunes; case 2: horasCortesia = ht.horasCortesiaMartes ?? 0; return ht.HorarioMartes; case 3: horasCortesia = ht.horasCortesiaMiercoles ?? 0; return ht.HorarioMiercoles; case 4: horasCortesia = ht.horasCortesiaJueves ?? 0; return ht.HorarioJueves; case 5: horasCortesia = ht.horasCortesiaViernes ?? 0; return ht.HorarioViernes; case 6: horasCortesia = ht.horasCortesiaSabado ?? 0; return ht.HorarioSabado; case 7: horasCortesia = ht.horasCortesiaDomingo ?? 0; return ht.HorarioDomingo; } } return String.Empty;


It actually has a reason of having all those properties ("ht" is a business entity object which comes from a database, and those are fields in the database), but still :-)

PS: "diaSemana" = "day of week", "Lunes...Domingo" = week days in spanish :-)
added on the 2009-02-15 22:29:35 by Jcl Jcl
Always the classic:

BB Image
added on the 2009-02-15 22:29:42 by kb_ kb_
Jcl: You code in spanish, and you admit having written that horrible piece of code? May the coding gods have mercy on you!
every1 once started...

and: didn´t i know this thread has it´s right_to_exist ?

learning_by_reading i tell you ! ( use searchmachines wisely ! )
Some null pointers...

Note the explicit if statement that checks wether life is null.
Note the explicit usage of life before that statement.
Not my code :D And not my problem for long either

Code: private List validateLifeAssured(LifeAssuredRole_ABC life, boolean useMessages) throws Exception, ValidationException { List messages = new ArrayList(); Contract_ABC contract = life.getContract(); DateTime effectiveDate = contract.getEffectiveDate(); DateTime rateDate = contract.getRateDate(); String functionCode = productModelServices .getFunctionGroupForNewBusiness(effectiveDate, rateDate); Integer ageNextBirthday = null; if (life != null) { System.out.println("*v*v*v*v* (validateLifeAssuredList) "); System.out.println(life); ageNextBirthday = new Integer(calculationsServices .calculateAgeNextBirthday(((NaturalClient_ABC) life .getClient()).getDateOfBirth(), effectiveDate)); try { productModelServices.validateInvestmentTerm(new Integer( contract.getInvestmentTermInMonths()), ageNextBirthday, contract.getProductCode(), functionCode, effectiveDate, rateDate); } catch (Exception e) { if (useMessages) { messages.add(new ValidationMessage_ABC(contract, e .getMessage())); } else throw e; } } return messages; }


Same effect here...

Code: public Rider_INB getRider(Long id) throws Exception { Rider_INB rider = product_INBDao.getRider(id); Product_INB pr = rider.getRecurringProduct(); Contract_INB c = pr.getContract(); Portfolio_INB p = c.getPortfolio(); InvestoQuote_INB q = p.getInvestoQuote(); Intermediary_INB servicingBroker = new Intermediary_INB(q.getServicingBrokerCode(),q.getServicingBrokerHouse()); if (rider != null) { setRiderRetailClients(rider, servicingBroker); } return rider; }


And this one is a gem...
termYears o termMonths is null... we dont know which one... so let's use both

Code: public void updateTermYearsMonths(Integer termYears, Integer termMonths) { if (termYears == null || termMonths == null) { this.termInMonths = new Integer((termYears.intValue() * 12) + termMonths.intValue()); } else { this.termInMonths = null; } }


This is a nice one ... and not the only one lying around.
So your'e 100% sure an object is null and then go use it.

Code: if (getQuoteSession().getInvestmentDetailsPageSession() .getCurrentRecurringProduct() != null) { productCode = getQuoteSession().getInvestmentDetailsPageSession() .getCurrentRecurringProduct().getProductCode(); } else { productCode = getQuoteSession().getInvestmentDetailsPageSession() .getCurrentSingleProduct().getProductCode(); }


Not crazy or too stupid...
But after value is checked wether it's null... a little further on...
we just make sure anyways

Code: public static boolean isEmpty(Object value) { if (value == null) { return true; } if (value instanceof String) { String string = (String) value; if (string != null && !string.trim().equals("")) return false; else return true; } else { if (value != null) return false; else return true; } }


I remember once I offered to solve a problem, and was told to rather not, let the other guy fix it (null pointer) ... cause they rely on them to occur, I guess as a flow control
added on the 2009-02-16 06:43:41 by _TrXtR_ _TrXtR_
zeroshift, i'm happy you took it up :-)
added on the 2009-02-16 07:48:46 by skrebbel skrebbel
Quote:
Jcl: You code in spanish, and you admit having written that horrible piece of code? May the coding gods have mercy on you!

Actually, yesterday I found the following code in Graga's 3d engine:

Code: int modellertaelle; for(modellertaelle = 0; modellertaelle < Jorden.num_modeller; modellertaelle++) { if((modellertaelle > 0) && (modellertaelle < Jorden.num_modeller)) { u16* datahoved = (u16*)Jorden.models[i].datahoved; Jorden.models[i].num_punkter = datahoved[0]; Jorden.models[i].num_ansigter = datahoved[1]; Jorden.num_punkter += datahoved[0]; Jorden.num_ansigter += datahoved[1]; } }
added on the 2009-02-16 07:59:20 by skrebbel skrebbel
hahaha, I only coded in Spanish because of company requirements... not in my 3D engine! :-)

Belive it or not, the level of English-speaking people in Spain (even in the IT industry) is rather low... amazingly, that includes other programmers :)

Anyway, here's another one: notice the comment there. That was in production for 2 years (that's 2003 code) :)

Code: case MessageType.LoginSuccess: ClientLoggedOn = true; Inf.WriteLog("Logged on to Xtation Network"); ClientIssuedLogon = false; ReceivedFFT = true; ReceivedWaveData = true; ReceivedVideoStream = true; /** Jcl: WTF is this code doing here? For god's sake, please take all network queries to the querying loop and use this only for receiving. THIS IS A GREAT CANDIDATE FOR INFINITE LOOPS IF SOMETHING FAILS RIGHT AFTER LOGIN **/ // TODO: move this to the querying loop, add a state variable to check for initial querying QueryTimer(Data.ProjectionController.ControllerID); for(int i = 0; i < Data.ProjectionController.Decks.Count; i++) { QueryDeckCurrent(Data.ProjectionController.ControllerID, i); QueryDeckNext(Data.ProjectionController.ControllerID,i ); QueryDeckTransition(Data.ProjectionController.ControllerID, i); QueryDeckTransitionTime(Data.ProjectionController.ControllerID, i); QueryDeckSendAmount(Data.ProjectionController.ControllerID, i); QueryDeckSendMode(Data.ProjectionController.ControllerID, i); i++; } QueryTextFx(Data.ProjectionController.ControllerID); QueryText(Data.ProjectionController.ControllerID); break;

Now I'm not sure if I coded that or just added the comment, but still.

Of course, it was never moved :)
added on the 2009-02-16 08:17:57 by Jcl Jcl
Quote:

Now I'm not sure if I coded that or just added the comment, but still.


That's what SVN blame is for :)

This is one of mine:

Code: bool TowerLogic::isEffectBig() { int gameMode = g_gameEngine.GetGameMode(); bool modeAllowsBalconies = (m_pTower->m_buildBalconies && gameMode == BUILD_TOWER_4_CITY) || gameMode != BUILD_TOWER_4_CITY; bool balcony = ((m_towerHeight > 1) && (m_balconyCounter > 0) && ((m_balconyCounter % 4) == 3) && modeAllowsBalconies); return false; }
added on the 2009-02-16 09:31:53 by Preacher Preacher
Quote:
Code: int modellertaelle; for(modellertaelle = 0; modellertaelle < Jorden.num_modeller; modellertaelle++) { if((modellertaelle > 0) && (modellertaelle < Jorden.num_modeller)) { u16* datahoved = (u16*)Jorden.models[i].datahoved; Jorden.models[i].num_punkter = datahoved[0]; Jorden.models[i].num_ansigter = datahoved[1]; Jorden.num_punkter += datahoved[0]; Jorden.num_ansigter += datahoved[1]; } }
:O
Bored at work guys?

Life is so much better as a student ;)

Anyway, i guess you all know about http://thedailywtf.com/ ?
added on the 2009-02-16 11:11:39 by nerve nerve
And todays wtf is: BBcode requires links need to start with www, even when http:// is present...

lame :P
added on the 2009-02-16 11:17:31 by nerve nerve

login

Go to top