CodeSOD: Nothing Direct About directAddCartEntry

This post was originally published on this site

The Daily WTF

It’s old hat, but every function, every class, every code unit you write, should all have a single, well-defined purpose. “Do one thing, and do it well,” as it were.

Of course, sometimes, it’s easier said that done, and mindlessly following that advice can lead to premature abstraction, and then you’ll have quite a mess on your hands. Still, it’s good advice, and a great design goal, even if you don’t head straight there.

Marigold found some code which, well, has a long way to go. A looooooong way to go.

directAddCartEntry = function (matnr, menge,updateByField,m,redu){ var that=this; var produkt=new Object; var target = document.getElementById(‘content’); spinner.spin(target); if (produkt.BACK_PREIS!=undefined && produkt.BACK_PREIS!=””){ produkt.PREIS = produkt.BACK_PREIS } var Kundennummer = app.getModel(“userData”).getData().KUNDENNR; var Land = app.getModel(“userData”).getData().LAND; var Euland = app.getModel(“userData”).getData().ISTEULAND; var Kundennummer_u_Euland = Kundennummer+”|”+Euland+”|”+Land; var verpackungseinheit = “”; sap.ui.getCore().byId(“app”).getModel(“kategorie”).read(“/PRODUKT_SET(MATNR='”+matnr+”‘,VKORG='”+VKORG+”‘,SPRAS=’de’,KAMPAGNE='”+Kundennummer_u_Euland+”‘,VTWEG=’10’)?$expand=MERKMAL”,null,null,false,function(oData,response){ produkt=oData; var mindestbestellmenge = produkt.BOMRABATT; verpackungseinheit = produkt.VERPACKUNGSEINHEIT if (mindestbestellmenge!=”0.000 “&& mindestbestellmenge!=”” && mindestbestellmenge

To read the full article click on the 'post' link at the top.