• Space bar programmers 'paid more'
    65 replies, posted
Always use spaces just in-case someone's got different tab settings. Whether to keep it formatted consistently or to make it readable when someone's tab spacing is ridiculously high. Personally I use 2 character spacing, a lot also use 3.
The book did gave a list of reasons and circumstances where making comments was acceptable and neccesary, but stated that commenting was still something that needs to be minimized and used very sparingly I have been using this advice for some time and hasnt feelt the need to comment anything yet, even when returning to old code I always knew what everything does. But it does ultimately break down into personal preference and whats easier for you I guess.
[QUOTE=WhyNott;52377293]The book did gave a list of reasons and circumstances where making comments was acceptable and neccesary, but stated that commenting was still something that needs to be minimized and used very sparingly I have been using this advice for some time and hasnt feelt the need to comment anything yet, even when returning to old code I always knew what everything does. But it does ultimately break down into personal preference and whats easier for you I guess.[/QUOTE] Minimizing comments =/= write no comment. Your code becomes too hard to read if you comment every line, and it's also too hard to read if you write no comment. Many people in this thread has showed practical examples of how to properly comment your code. The key is to write comment for every major step on your program/function's logical flow to help the reader understand faster. This usually is enough for most cases.
Comments can help understand the [i]intent[/i] of a block of code in very concise snippets, which helps greatly when you know what your goal is when you're fixing a bug in it.
[QUOTE=NotMeh;52371754]what do you even mean by this? you will know the logic of any and all code "just by going through it", [B]regardless of how well it's written[/B] [/QUOTE] 1) Readibility is a thing 2) Jokes about Indian spaghetti code is a thing 3) Yeah, you can understand what "echo "Fuck you" " does in PHP, but when you have a fuckload of stuff going on in your function which takes variables from all over the code, it starts to get messy. I mean, how long will it take to figure out the logic of what this function does? This is something I've written (I'm still a horrible programmer, so extra-commenting stuff for me is necessity for regression) and before you all start yelling, I admit it's something what I could've done better, but I'm still comparatively new to JS, also Sharepoint is a goddamn bitch and requires extra hoops to cover [code] function onQuerySucceeded(sender, args) { var path = ''; var level = '1'; var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); var colNum = '0'; var box = ''; var levelCount = '0'; var colCount = '1'; while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); oListItem.get_item('Path'); if (oListItem.get_item('Path') != path) { cument.createElement('section'); var pathHeader = document.createElement('h2'); pathHeader.innerHTML = oListItem.get_item('Path'); containerBox.className = "pathColumn"; document.getElementById("testField").appendChild(containerBox); containerBox.appendChild(pathHeader); colNum++; var boxMain = document.createElement("section") boxMain.className = "path"; pathHeader.setAttribute("onclick", "check("+colNum+")"); } var path = oListItem.get_item('Path'); listItemInfo = oListItem.get_item('Title'); if (level === oListItem.get_item('Level')) { box.className = "sameLevel"; levelCount++; } else {//(level != oListItem.get_item('Level')) { var boxLine = document.createElement("section"); if (levelCount > 0) { box.className = "sameLevel"; levelCount = 0; } else { box.className = ""; } } box = document.createElement("span"); var desc = document.createTextNode(listItemInfo); box.setAttribute("onclick", "openPageInDialog(true, true, true,\' https://sharepoint.net/sites/test/Lists/Career/DispForm.aspx?ID="+oListItem.get_item('ID')+"\')"); box.appendChild(desc); boxLine.appendChild(box); boxMain.appendChild(boxLine); document.getElementById('main').appendChild(boxMain); level = oListItem.get_item('Level'); boxLine.className = "level-"+level; } } [/code]
Sorry, you need to Log In to post a reply to this thread.