Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,420 members, 7,815,950 topics. Date: Thursday, 02 May 2024 at 09:55 PM

Is There Any Prof. Programmer That Could Criticize This My Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Is There Any Prof. Programmer That Could Criticize This My Code (988 Views)

Need Android Programmer That Can Teach Me How To Program Android App / I Need A Programmer That Can Create Live Video Chat / I Am Looking For Programmer That Are Way Smarter Than Me (2) (3) (4)

(1) (Reply) (Go Down)

Is There Any Prof. Programmer That Could Criticize This My Code by smithsteady(m): 2:23pm On Sep 09, 2013
Is there any prof. programmer that could criticize this my code, or help me improve the quality. I believe dat i'm not perfect there are guys out there better than me. this jQuery and Javascript


$(function () {

var PledgeTypeFrequency = {
startDateWrapper: $("#wrapper-start-date"wink,
dueDateWraper: $("#wrapper-due-date"wink,
wrapper: $("#wrapper"wink,
dropDown: $("#pledge-freq-select"wink
}

var chkReminder = $("#chkReminder"wink;
var remindPeriod = $(".remind-period"wink;
var pledgeType={
amount:$("#amount-wrapper"wink,
desc: $("#desc-wrapper"wink,
wrapper: $("#wrapper2"wink,
dropDown: $("#pledge-type"wink
};
function IsShowRemindPeriod(condition)
{
if (condition.is(':checked'))
remindPeriod.slideDown(1000);
else
remindPeriod.slideUp(1000);
}
IsShowRemindPeriod(chkReminder);


function CommonOperation(obj1,obj2)
{
obj1.css({ "display": "none" });
obj2.css({ "display": "none" });
}
function PledgeFreqDisplay()
{
var selectedVal = $("#pledge-freq-select :selected"wink.text();
if (selectedVal == "One Time"wink
PledgeTypeFrequency.wrapper.empty().append(PledgeTypeFrequency.dueDateWraper.css({ "display": "block" }));

else if (selectedVal == "Select"wink
CommonOperation(PledgeTypeFrequency.dueDateWraper, PledgeTypeFrequency.startDateWrapper);
else
PledgeTypeFrequency.wrapper.empty().append(PledgeTypeFrequency.startDateWrapper.css({ "display": "block" }));
}
function PledgeTypeDisplay()
{
var selectedPledge = $("#pledge-type :selected"wink.text();
if (selectedPledge === "Money"wink
pledgeType.wrapper.empty().append(pledgeType.amount.css({ "display": "block" }));
else if (selectedPledge == "Select"wink
CommonOperation(pledgeType.amount, pledgeType.desc);
else
pledgeType.wrapper.empty().append(pledgeType.desc.css({ "display": "block" }));

}

PledgeFreqDisplay();
PledgeTypeDisplay();
pledgeType.dropDown.change(function () {
PledgeTypeDisplay();
});

PledgeTypeFrequency.dropDown.change(function () {
PledgeFreqDisplay();

});

chkReminder.bind("click",function () {
IsShowRemindPeriod(chkReminder);
});

})
Re: Is There Any Prof. Programmer That Could Criticize This My Code by Nobody: 3:04pm On Sep 09, 2013
Oga, use pastebin to show ur code to ppl... There are forums you can go to and they will be there to help you polish ur code realtime.

1 Like

Re: Is There Any Prof. Programmer That Could Criticize This My Code by Nobody: 10:18am On Sep 10, 2013
$(function () {

var PledgeTypeFrequency = {
startDateWrapper: $("#wrapper-start-date"wink,
dueDateWraper: $("#wrapper-due-date"wink,
wrapper: $("#wrapper"wink,
dropDown: $("#pledge-freq-select"wink
}
//First of all you are creating too many overheads by using jQuery to fetch elements with id, because jQuery selector has much going in it
check the http://jsperf.com/getelementbyid-vs-jquery-id/44

var chkReminder = $("#chkReminder"wink;
var remindPeriod = $(".remind-period"wink;
var pledgeType={
amount:$("#amount-wrapper"wink,
desc: $("#desc-wrapper"wink,
wrapper: $("#wrapper2"wink,
dropDown: $("#pledge-type"wink
};
function IsShowRemindPeriod(condition)
{
if (condition.is(':checked'))
remindPeriod.slideDown(1000);
else
remindPeriod.slideUp(1000);
}
IsShowRemindPeriod(chkReminder);


function CommonOperation(obj1,obj2)
{
obj1.css({ "display": "none" }); // you can get faster execution with Vanailla JS ob.style.display="none";
obj2.css({ "display": "none" });
}
function PledgeFreqDisplay()
{
var selectedVal = $("#pledge-freq-select :selected"wink.text();
if (selectedVal == "One Time"wink
PledgeTypeFrequency.wrapper.empty().append(PledgeTypeFrequency.dueDateWraper.css({ "display": "block" }));

else if (selectedVal == "Select"wink
CommonOperation(PledgeTypeFrequency.dueDateWraper, PledgeTypeFrequency.startDateWrapper);
else
PledgeTypeFrequency.wrapper.empty().append(PledgeTypeFrequency.startDateWrapper.css({ "display": "block" }));
}
function PledgeTypeDisplay()
{
var selectedPledge = $("#pledge-type :selected"wink.text();
if (selectedPledge === "Money"wink
pledgeType.wrapper.empty().append(pledgeType.amount.css({ "display": "block" }));
else if (selectedPledge == "Select"wink
CommonOperation(pledgeType.amount, pledgeType.desc);
else
pledgeType.wrapper.empty().append(pledgeType.desc.css({ "display": "block" }));

}

PledgeFreqDisplay();
PledgeTypeDisplay();
pledgeType.dropDown.change(function () {
PledgeTypeDisplay();
});

PledgeTypeFrequency.dropDown.change(function () {
PledgeFreqDisplay();

});

chkReminder.bind("click",function () {
IsShowRemindPeriod(chkReminder);
});

})

//To be frank i really see nothing with your code except you tend to use too much uneccessary
Jquery codes where normal Javascript code would suffice, its all about optimization but the code is good in my honest opinion except
Re: Is There Any Prof. Programmer That Could Criticize This My Code by smithsteady(m): 1:04pm On Sep 10, 2013
Thanks u my pals.
Re: Is There Any Prof. Programmer That Could Criticize This My Code by kadeer: 12:21am On Sep 11, 2013
@OP, code seems light weight from an imagined point of view of what the DOM looks like looking at the code. My advice, continued use of your cached selectors. Also, as you further further further (repetition intentional) progress, begin to decouple the UI elements from the controller actions. You know View, Controller logic separation. Not saying roll or use a client side MVC project, just something like this.

// router
app = $({});

// controller
app.on("pledgeType.change", PledgeTypeDisplay)
app.on("PledgeTypeFrequency.change", PledgeTypeFrequency)

// view
pledgeType.dropDown.change(function () {
app.trigger("pledgeType.change"wink;
});

Also like to know your reason of storing jQuery ref in objects PledgeTypeFrequency, and pledgeType. Scoping I imagine?




Errrrr @pc guru, to call out using $("#id-selector"wink, especially for the reason of creating "too many overheads" I'm not sure is valid criticism, coupled with the fact that those calls are one off, at the beginning of the code run, and cached in a variable. Browsers (mine here Chrome 29.0) ran a $("#foo"wink from your linked test 524,916 times in 1 (one) second. Even IE6 on WinXP should achieve a pretty decent iteration count.

Also jQuery's use would be considered valid considering he runs animations within the script.

@pc guru, just couldn't pass without pointing those reasons out.
Re: Is There Any Prof. Programmer That Could Criticize This My Code by Nobody: 8:50am On Sep 11, 2013
@kadeer well true its a one-off thing, sometimes i tend to switch to normal JS if i am getting an Element that is already known like id prob dojo habits, but since it triggers once, indeed there is no overhead, the jsperf only hints on the situation where its a multiple call so yeah you are right on that. just a performance freak especially these days where JavaScript gets heavy easily. but point taken and noted. how's the Backbone world smiley
Re: Is There Any Prof. Programmer That Could Criticize This My Code by smithsteady(m): 4:32pm On Sep 11, 2013
I appreciate all your corrections my heroes

(1) (Reply)

Xml Assignment / Cloudbridge LLC (A Young Start Up) Needs A PHP Programmer / Interesting Article On Principles Of Modern Web Development. By Joe Stangarone

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.