The Joys Of Programming

Second-ever coding interview done! This time was an automated hackerrank thing, with a one-hour time limit, and the fact that I finished in 13 minutes leaves me with some questions about the company I applied to.

I'm looking at an IF/ELSEIF/ELSE condition spread across 40 lines of code. The IF and ELSEIF both have an IF/ELSE condition inside of them. Yet, every single path ends up calling the exact same method with the exact same parameters.

Whoever did this repeated this same pattern four times in the same method.

That thing is a masterpiece.

When I see stuff like that, I feel the dismay, but also a tingly thrill because I love deleting code.

I want to print it and frame it, its pointlessness is beautiful.

Sounds like fodder for The Daily WTF.

Probably impossible to unit test that.

PWAlessi wrote:

Probably impossible to unit test that.

I don’t think the place I’m contracting at has ever heard of unit testing. Or code review.

At least there's version control. (I hope.)

Yep, they have folders named version1, 20210615, v3, 9182020 and so on.

Ted wrote:

At least there's version control. (I hope.)

Yes, the build-in SAP version control (which is archaic but functional), however...

Instead of deleting obsolete code and letting the version control remember it for them, it's just commented. So there are some areas where half of the lines are commented dead code. Plus they have this weird habit of just adding the transport number at the end of the line where the line was added (or commented), which is just confusing.

There are a lot of comments in the code, 90% of them completely useless. This codebase is about 20 years old, and in some spots if feels like everyone at the company had a ride at one point or another. It's a gigantic mess, one that I'm reverse engineering so it can be redone with a non-SAP technology.

.bak
.bak20230312
.bak20220123
.bak.bak
.old.bak

I hate the scientists I work with.

Lest anyone think i'm joking, here's an actual random directory listing on one of the servers:

PGF_put_gps
PGF_put_gps.20150817
PGF_put_gps.20201014
PGF_put_gps_day
PGF_put_gps_day.20160628
PGF_put_gps_day.20181005
PGF_put_gps_day.20201014
PGF_put_gps_day_site
PGF_put_gps_day_site.20201013
PGF_put_gps.log
PulseChannel.class
PulseChannel.java
PulseRelay
PulseWebRelay_HUAL
raw2rinex_5700
raw2rinex_5700.13nov12
raw2rinex_5700.20160426
raw2rinex_5700_iaj
raw2rinex_5700_split
raw2rinex_bnx
raw2rinex_netr9
raw2rinex_sep
raw2rinex_spp
raw2rinex_t01
raw2rinex_t02
raw2rinex_t02.20181126
redo_1sta.csh
RNX2CRX
runpkr00
runpkr00.old

bobbywatson wrote:

I'm looking at an IF/ELSEIF/ELSE condition spread across 40 lines of code. The IF and ELSEIF both have an IF/ELSE condition inside of them. Yet, every single path ends up calling the exact same method with the exact same parameters.

Whoever did this repeated this same pattern four times in the same method.

That thing is a masterpiece.

The really sad thing is that most modern compilers/interpreters will optimize that and remove the IF/ELSEIF/ELSE condition completely. Sh*t, they did that 20 years ago when I last cut code professionally. So there's no incentive to write decent code.

bobbywatson wrote:

SAP... This codebase is about 20 years old...

Ah, okay; it all makes sense now.

I've slung a little bit of ABAP/4, a long time ago.

I feel your pain.

Maybe I’m old but I was already a few years into my career 20 years ago and I’m pretty sure no one I worked with would have written code like that. And it sure wouldn’t have passed review. However, it does remind me of the code I wrote when I was hacking text adventures in BASIC at 7 years old :).

bobbywatson wrote:

I'm looking at an IF/ELSEIF/ELSE condition spread across 40 lines of code.

IF ELSE IF ELSE IF ELSE ELSE IF ELSE GEFRAGT ELSE IF ELSE GEFRAGT ELSE IF ELSE GEFRAGT UND ICH HAB NICHTS GESAGT
Ted wrote:
bobbywatson wrote:

SAP... This codebase is about 20 years old...

Ah, okay; it all makes sense now.

I've slung a little bit of ABAP/4, a long time ago.

I feel your pain.

I could complain about SAP all day, but, all in all, I'd say going there was probably a good move in the long term. I've been putting bread on my table and a roof over my head for 16 years at this point and, in 3 years, I should be able to reach financial independence and retire before I turn 50 (and would've gotten there sooner had I not been so stupid), so thanks SAP I guess

(Would I do it again knowing what some of those 16 years would be like? That's a whole different question.)

Comparing a structure and a single field? Really?

Jesus f*ck.

Guten `ABEND`!

No, ABAP lets you do it no problem, but the results are not going to be what you expect! (I’m not even sure the compiler issues warnings about this.)

This week has certainly been… interesting.

https://a.hollywood.computer/

My hidden gem of the week.

Hollywood is a utility that will split a computer console into multiple panes of genuine technical melodrama, perfectly suitable for busy-looking computers in the background.

But that's what my terminal normally looks like...

Lots and lots of eye strain.

merphle wrote:

But that's what my terminal normally looks like...

I'm confused, where's the Hollywood here again?

Hoping someone can help with this PHP error. I haven't touched PHP in a very long time but we need to upgrade and after the upgrade we are getting the error:
count(): Parameter must be an array or an object that implements Countable

public function do_events_search()
{
$filters = $this->request->query->all();
$model = $this->events;
if ($filters['query'] && count($filters['query'])) {
$model->filter(false, ' ((B.eTeaser like "%' . addslashes(trim($filters['query'])) . '%") or (B.eTitle like "%' . addslashes(trim($filters['query'])) . '%") or (B.eTags like "%' . addslashes(trim($filters['query'])) . '%")) ');
}
// only show active & future dates
$model->filter('B.eActive', 1);
$model->sortBy('A.StartDate');
$events = $model->get(0);
$this->set('events', $events);
}

I tried adding is_countable
if ($filters['query'] && is_countable($filters) && count($filters['query']) >0) {
but still get the error.
Any suggestions?

Have you tried using AI for such questions? For my money this is what it's best at.

To wit, I pasted your post verbatim into (free) chatGPT and its answer looks reasonable at a glance:

...In your code, you are trying to count the $filters['query'] array, but it seems you want to check if it's set and not empty before counting it. You can modify your code as follows:
...
// Check if 'query' key exists and is not empty in $filters array
if (isset($filters['query']) && is_array($filters['query']) && count($filters['query']) > 0) {

Of course AI being AI, you'll want to check whether those "isset" and "is_array" globals exist or not

Thank you. I didn't even think to put it into ChatGPT despite using it to write some sql statements.

TL;DW: Use Vim

Spoiler:

I didn’t actually watch the video but that’s what it should be

I've just realized that half my personal projects are indented by two spaces, and half are indented by four spaces, and I can't decide which to align on. Somehow they now both look wrong.

Is three spaces out of the question? That's crazy talk right?

Tabs vs spaces ...... Fight!