std::string str ("Nobody cares about development...");

Noodles

At least I tried to try.
Joined
Sep 20, 2018
Messages
1,605
Location
Illinois
SL Rez
2006
Joined SLU
04-28-2010
SLU Posts
6947
While coding: "I'll come.back and add comments once it's done and working."

When it's done and working: "No one touch this house of cards or add anything, for some reason any more 'g's added and the whole thing crashes."
 
  • 1Agree
  • 1LOL
Reactions: Soen Eber and bubblesort

bubblesort

Well-known member
Joined
Nov 16, 2018
Messages
1,592
I've been studying how to set up express servers and use EJS to embed javascript and all that. On Thursday, I hit a crazy error.

My Setup:

I'm on Windows 10, running gitbash, serving my pages with express and using nodemon to start the server and restart automatically when I change index.js. I have index.js set up to read page data from a .json file, then feed it to a home.ejs page, so my title attribute in the head of the page is <title><%=title%></title>, then the headline of the page is <h1><%=headline%></h1>. That's really all the ejs I used, because I'm just learning to set things up and tinker.

The Result:

The browser parses this perfectly! The broswer console acts like everything is fine. The terminal, on the other hand...

The terminal pitches a fit. Every time I visit the page, I get this:

Bash:
ReferenceError: D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\views\home.ejs:7
    5|     <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6|     <meta name="viewport" content="width=device-width, initial-scale=1.0">
>> 7|     <title><%=title.toUpperCase()%></title>
    8|     <link rel="stylesheet" href="/css/style.css">
    9| </head>
    10| <body>

title is not defined
    at eval (eval at compile (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\ejs\lib\ejs.js:662:12), <anonymous>:12:25)
    at home (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\ejs\lib\ejs.js:692:17)
    at tryHandleCache (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\ejs\lib\ejs.js:272:36)
    at View.exports.renderFile [as engine] (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\ejs\lib\ejs.js:489:10)
    at View.render (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\express\lib\view.js:135:8)
    at tryRender (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\express\lib\application.js:640:10)
    at Function.render (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\express\lib\response.js:1012:7)
    at D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\index.js:16:13
    at Layer.handle [as handle_request] (D:\Code\WebDev\EJS Problems\expresspractice02_9-16-2021\node_modules\express\lib\router\layer.js:95:5)

I don't even know how to begin troubleshooting this. I'm messing with variables and triple checking the json and express docs, asking anybody I can find on discord what the hell this is, because it's not like the variable is not working. The browser thinks it's working perfectly! For some reason node just hates it. After troubleshooting it for days, I tried something different...

Today, I spent the day setting up a linux mint vm, just to see if maybe windows 10 is the culprit. The only reason it took all day is because VirtualBox hates my network card. Anyway... when I brought the code into linux, I had the exact same problem.

The Fix:

I gave up on those files, and just coded up a brand new page from scratch, with all the same types of things... and it runs perfectly! No errors, anywhere! So I start looking at the differences between the old and new files. There's one tiny little if-else statement I added to the one that works, that wasn't there in the one that's broken. So I put the if-else in the broken file, and... it works!

This is the broken app.get:
JavaScript:
app.get('/:page', (req, res) => {
    const {page} = req.params;
    const data = pageData[page];
    res.render('home', {...data});
})
This is the working app.get:
JavaScript:
app.get('/:page', (req, res) => {
    const {page} = req.params;
    const data = pageData[page];
    if(data){   //if there is a valid path
        res.render('home', {...data});
    } else {
        res.render('notfound', {page});
    }
})
WHY?!?!?! I have no idea! Back end issues are crazy.

If anybody here has any insight at all into what happened here, I'd really like to know. I've searched everywhere, and I'm pretty much giving up at this point, and moving on to study database stuff. It would be really nice to know why the bad code is bad, though. (if you can recommend a book that would help me, I would appreciate that, too!)
 

bubblesort

Well-known member
Joined
Nov 16, 2018
Messages
1,592
Followup... I tried to forget the problem for the rest of the evening and relax with a couple of whiskies... then decided I really should comment up the code with an explaination of what happened, so I can look at it later. So I drop like 20 likes of comments on the broken code, explaining how it's broken and how to fix it and all that. Then I run it one last time to make sure it's good and broken.

It works!

I try to break it again by deleting the magic comments that fixed it.

It still works!

I have no idea how this happened, but I fixed code with comments so well, that it's still fixed after I delete the comments. Maybe I had a typo and typed a magical incantation in my comments. Maybe I'm just better at debugging when I'm half drunk, I don't know.

All I know is this is too weird to troubleshoot. This problem leads to nothing but madness. I'm going to forget it happened and do something else with my time, LOL
 

Argent Stonecutter

Emergency Mustelid Hologram
Joined
Sep 20, 2018
Messages
3,452
Location
Coonspiracy Central, Noonkkot
SL Rez
2005
Joined SLU
Sep 2009
SLU Posts
20780

Noodles

At least I tried to try.
Joined
Sep 20, 2018
Messages
1,605
Location
Illinois
SL Rez
2006
Joined SLU
04-28-2010
SLU Posts
6947
Yeah, that phone number likely is t the worst option.

Type a number, tab to the next box, type a number, and so on. I could think of worse input methods.
 

bubblesort

Well-known member
Joined
Nov 16, 2018
Messages
1,592
Yeah, that phone number likely is t the worst option.

Type a number, tab to the next box, type a number, and so on. I could think of worse input methods.
A few years ago, on Reddit, it was kind of a fad to try to come up with the worst interface for phone number form elements. Here's a collection of memorable attempts.

 
  • 1ROFL
Reactions: Noodles

Soen Eber

Vatican mole
VVO Supporter 🍦🎈👾❤
Joined
Sep 20, 2018
Messages
1,524
What is this 'documentation' you speak of?
Oh, it's right ... no, that's Oracle blathering at C-level executives. Aha! It's ... oh wait, now Oracle is blathering at sales team leads, saying how many more customers they can get if they ... maybe this? Oh, no, sorry it's a 1 on 1 with Oracle's marketing lead talking with an Oracle development manager. No, this is ... no, that's from 2007. Oh, here's an Oracle developer white page, maybe ... [this feature is no longer supported, please see link] *click* Um, boss, do we really want to pay Oracle an $800 seat license for this? They've spun it off to a new product. Maybe if I looked here ... no, sorry, it's another high-level exec advertising brochure. Hey, this newsgroup says there's an open-souce solu. Wait, it's abandonware. Well, Adobe put out something that looks like just the ... oh, Oracle bought it.
 
  • 1Agree
Reactions: Khamon

Ashiri

√(-1)
Joined
Sep 20, 2018
Messages
893
Location
RL: NZ
SL Rez
2007
SLU Posts
-1
The company I work for has some of the worst user interfaces I have seen.

The latest was for putting in vaccination details. To enter my birthdate they had a two pane calendar with the left pane being a date grid for a given month, the right being a month grid for a given year. To enter the date it was necessary to up arrow to the appropriate year, then select the month. The left pane then changes to that month and the day can be entered. Entering the vaccination date was a far simpler exercise of entering day/month/year (though the field initialised as NaN/NaN/NaN)
 

Free

Chatting with JFK Jr.
VVO Supporter 🍦🎈👾❤
Joined
Sep 22, 2018
Messages
22,913
Location
Moonbase Caligula
SL Rez
2008
Joined SLU
2009
SLU Posts
55565

Bartholomew Gallacher

Well-known member
Joined
Sep 26, 2018
Messages
3,291
SL Rez
2002
The life of an Oracle database developer at Oracle:

It is close to 25 million lines of C code.
What an unimaginable horror! You can't change a single line of code in the product without breaking 1000s of existing tests. Generations of programmers have worked on that code under difficult deadlines and filled the code with all kinds of crap.
Very complex pieces of logic, memory management, context switching, etc. are all held together with thousands of flags. The whole code is ridden with mysterious macros that one cannot decipher without picking a notebook and expanding relevant pats of the macros by hand. It can take a day to two days to really understand what a macro does.
Sometimes one needs to understand the values and the effects of 20 different flag to predict how the code would behave in different situations. Sometimes 100s too! I am not exaggerating.
The only reason why this product is still surviving and still works is due to literally millions of tests!
Here is how the life of an Oracle Database developer is:
- Start working on a new bug.
- Spend two weeks trying to understand the 20 different flags that interact in mysterious ways to cause this bag.
- Add one more flag to handle the new special scenario. Add a few more lines of code that checks this flag and works around the problematic situation and avoids the bug.
- Submit the changes to a test farm consisting of about 100 to 200 servers that would compile the code, build a new Oracle DB, and run the millions of tests in a distributed fashion.
- Go home. Come the next day and work on something else. The tests can take 20 hours to 30 hours to complete.
- Go home. Come the next day and check your farm test results. On a good day, there would be about 100 failing tests. On a bad day, there would be about 1000 failing tests. Pick some of these tests randomly and try to understand what went wrong with your assumptions. Maybe there are some 10 more flags to consider to truly understand the nature of the bug.
- Add a few more flags in an attempt to fix the issue. Submit the changes again for testing. Wait another 20 to 30 hours.
- Rinse and repeat for another two weeks until you get the mysterious incantation of the combination of flags right.
- Finally one fine day you would succeed with 0 tests failing.
- Add a hundred more tests for your new change to ensure that the next developer who has the misfortune of touching this new piece of code never ends up breaking your fix.
- Submit the work for one final round of testing. Then submit it for review. The review itself may take another 2 weeks to 2 months. So now move on to the next bug to work on.
- After 2 weeks to 2 months, when everything is complete, the code would be finally merged into the main branch.
The above is a non-exaggerated description of the life of a programmer in Oracle fixing a bug. Now imagine what horror it is going to be to develop a new feature. It takes 6 months to a year (sometimes two years!) to develop a single small feature (say something like adding a new mode of authentication like support for AD authentication).
The fact that this product even works is nothing short of a miracle!
I don't work for Oracle anymore. Will never work for Oracle again!

 

Bartholomew Gallacher

Well-known member
Joined
Sep 26, 2018
Messages
3,291
SL Rez
2002
Please note that not I am working for Oracle - this is merely the inside report of somebody who did and shared his insight on the internet. Which is why I also linked the original post.
 
  • 1Grumpy Cat
Reactions: Free

Argent Stonecutter

Emergency Mustelid Hologram
Joined
Sep 20, 2018
Messages
3,452
Location
Coonspiracy Central, Noonkkot
SL Rez
2005
Joined SLU
Sep 2009
SLU Posts
20780
I'm going to have to get a hacker news account to upvote most of those comments.
 
  • 1Agree
Reactions: Khamon