1. DLP Flash Christmas Competition + Writing Marathon 2024!

    Competition topic: Magical New Year!

    Marathon goal? Crank out words!

    Check the marathon thread or competition thread for details.

    Dismiss Notice
  2. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice
  3. Introducing for your Perusing Pleasure

    New Thread Thursday
    +
    Shit Post Sunday

    READ ME
    Dismiss Notice

Beginning in Programming

Discussion in 'Tech Support' started by Agent, May 20, 2018.

  1. Lord Ravenclaw

    Lord Ravenclaw DLP Overlord Admin DLP Supporter

    Joined:
    Apr 2, 2005
    Messages:
    4,372
    Location:
    Denver, CO
    Like anything (including Knuth's oft repeated and misunderstand statement about premature optimization), everything in moderation. The hate around GOTOs really stems from non-local GOTOs (and Dijkstra's scathing dislike of them) where it became really really hard to reason about the flow of your program.

    Knuth has really good article, "Structured Programming with go to Statements" (pdf) that talks about the whole situation.

    As an example of something made considerably easier with goto (often disguised as "break <label>", right from the Java documentation:

    Code:
    class ContinueWithLabelDemo {
        public static void main(String[] args) {
    
            String searchMe = "Look for a substring in me";
            String substring = "sub";
            boolean foundIt = false;
    
            int max = searchMe.length() -
                      substring.length();
    
        test:
            for (int i = 0; i <= max; i++) {
                int n = substring.length();
                int j = i;
                int k = 0;
                while (n-- != 0) {
                    if (searchMe.charAt(j++) != substring.charAt(k++)) {
                        continue test;
                    }
                }
                foundIt = true;
                    break test;
            }
            System.out.println(foundIt ? "Found it" : "Didn't find it");
        }
    }
    These are gotos, but have their purpose.
     
  2. Heleor

    Heleor EsperJones DLP Supporter

    Joined:
    Mar 3, 2006
    Messages:
    1,431
    Location:
    Seattle, WA
    Note: break/continue do not require labels.

    Code:
    for (int i = 0; i < 10; i++) {
      if (i == 3) break;
    }
    
    It can become useful if you have multiple nested loops and you want to break out of the entire construct (2D arrays are a great example) but in my years of professional Java development I have never seen the "break label" version in any production code.
     
  3. Lord Ravenclaw

    Lord Ravenclaw DLP Overlord Admin DLP Supporter

    Joined:
    Apr 2, 2005
    Messages:
    4,372
    Location:
    Denver, CO
    It's rare you can't structure it in another way. If you've ever used Guava, there's a number of places it happens. I mostly see it in algorithm-heavy code -- in Guava, it's often because of microbenchmarks found something was a bit faster that way.
     
  4. Jarizok

    Jarizok Auror DLP Supporter

    Joined:
    Sep 22, 2015
    Messages:
    632
    Gender:
    Male
    Location:
    Deventer
    I have succesfully passed all three tests of the first six weeks (basic programming, SQL & databases and object oriented programming). This means that I'll be allowed to continue on to the next phase, which will largely consist of group projects.

    The amount of stuff I've learned in 5 weeks (we had one week off) is kinda crazy, but I'm still loving it. Don't love DOAs as much though. Still kinda don't really understand what they're really for, even if I can use 'm.
     
  5. Jarizok

    Jarizok Auror DLP Supporter

    Joined:
    Sep 22, 2015
    Messages:
    632
    Gender:
    Male
    Location:
    Deventer
    Introductions to Git, MVC and JavaFX today. I can suddenly imagine the skeletons of so much software I've been using forever now. #Feelsgoodman
     
  6. Jarizok

    Jarizok Auror DLP Supporter

    Joined:
    Sep 22, 2015
    Messages:
    632
    Gender:
    Male
    Location:
    Deventer
    We started a new project last week. We’re building a web application, so now we need to learn some html, css and javascript as well as work with a shitload of new libraries and frameworks (Spring stuffs, Hibernate). It’s a lot to take in all at once, but I guess we do have 8 weeks to get the hang of it.

    The internet is my oyster!
     
  7. Lord Ravenclaw

    Lord Ravenclaw DLP Overlord Admin DLP Supporter

    Joined:
    Apr 2, 2005
    Messages:
    4,372
    Location:
    Denver, CO
    > shitload of new libraries and frameworks (Spring stuffs, Hibernate)

    Yep, there is indeed a shitload to learn there. Those are some very heavy frameworks, don't feel bad if it isn't clear immediately.
     
  8. Jarizok

    Jarizok Auror DLP Supporter

    Joined:
    Sep 22, 2015
    Messages:
    632
    Gender:
    Male
    Location:
    Deventer
    Soooo... I'm stuck.

    I have two tables on my html page. One is filled from the database via Thymeleaf with a list of ${modules}. What I want to do is I want to be able to select x amount of modules in table 1 and move them to table 2 via Javascript. One by one would be perfectly acceptable, but I can't even get that to work.

    The html:
    <div>
    <table id="jobOffers" align="left">
    <thead>
    <tr>
    <th onclick="sortTable(0, 'A', 'availableModules')" width="70%" >Module</th>
    <th onclick="sortTable(1, 'N', 'availableModules')" width="30%" >Uren</th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="module: ${modules}" onClick="HighLightTableRow(this,'#c9cc99','cc3333');">
    <td th:text="${module.name}" onclick="selectModule()">Name</td>
    <td th:text="${module.hours}" onclick="selectModule()">Hours</td>
    </tr>
    </tbody>
    </table>
    <table id="jobOffersSent" align="right">
    <thead>
    <tr>
    <th onclick="sortTable(0, 'A', 'selectedModules')" width="70%" >Module</th>
    <th onclick="sortTable(1, 'N', 'selectedModules')" width="30%" >Uren</th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="module: ${selectedModules}" onClick="HighLightTableRow(this,'#c9cc99','cc3333');">
    <td th:text="${module.name}" onclick="deselectModule()">Name</td>
    <td th:text="${module.hours}" onclick="deselectModule()">Hours</td>
    </tr>
    </tbody>
    </table>
    </div>

    I'm pretty sure the issue is with my Javascript, as I dont have a clue what I'm doing there:
    function selectModule() {
    var table, rows, i, x;
    table = document.getElementById(jobOffers);
    rows = table.rows;
    for (i = 1; i < (rows.length - 1); i++) {
    x = rows.getElementsByTagName("TD");
    x.addEventListener("click", function(){
    selectTargetModule(x);
    });
    }
    reload();
    }

    function deselectModule() {
    var table, rows, i, x;
    table = document.getElementById(jobOffersSent);
    rows = table.rows;
    for (i = 1; i < (rows.length - 1); i++) {
    x = rows.getElementsByTagName("TD");
    x.addEventListener("click", function(){
    deselectTargetModule(x);
    });
    }
    reload();
    }

    function selectTargetModule() {
    [[${selectedModules}]].add(x);
    [[${modules}]].remove(x);
    }

    function deselectTargetModule() {
    [[${modules}]].add(x);
    [[${selectedModules}]].remove(x);
    }

    function reload(){
    var container = document.getElementById(jobOffers);
    var container2 = document.getElementById(jobOffersSent);
    var content = container.innerHTML;
    var content2 = container2.innerHTML;
    container.innerHTML = content;
    container2.innerHTML = content2;
    }

    If anyone has any pointers I'd be eternally grateful.

    --- Post automerged ---
    What I was trying to do yesterday seems quite impossible. Found a workaround that does work, so all good tho.
     
Loading...