There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

Eufalconimorph , in ways to close vim

cat /dev/zero > “/proc/$(pidof vim)/mem” is my favorite dumb way. Clear its memory, wait for the segfault.

z3n0x , in rule
@z3n0x@feddit.de avatar
TheSaneWriter , in rule
@TheSaneWriter@lemmy.thesanewriter.com avatar

Honestly, this is a good rule for programming in general. With user input, make sure it’s in its own area where it can’t interact with anything else and make sure to read and process in such a way that it can’t fuck with the operation of the program.

CanadaPlus , in a brain is a network of if()

Yes, both of those words can be argued to apply in a vacuum. “AI” has started to intrinsically mean neural nets now, though.

As for the title: Lol, look at this guy who doesn’t even loop. What are you going to do, halt on top of me?

ImplyingImplications , in unrolling loops is efficient, right?
potoo22 , in unrolling loops is efficient, right?

In my first CS class, the professor announced an extra credit project due at the end of the semester. It was to create a formatted terminal calendar given a year from user input. I finished it after learning about condition but before I learned about classes… or functions… or loops… or searching the internet… partially. I searched how leap years worked, but didn’t bother to search for code (Stack Overflow didn’t exist yet)

Anyway, long ass program with each month hard-coded with 7 possible calendars for each month depending on the first day of the week. Lots of copy and paste. Professor was speechless, but accepted it.

ICastFist ,
@ICastFist@programming.dev avatar

“It’s not stupid if it works”

coloredgrayscale , in unrolling loops is efficient, right?

300 nested if statements, (…) added another 5000 nested if statements.

At this point I want to doubt that they actually wrote it themselves, vs writing a metaprogram to generate the code.

selawdivad , in unrolling loops is efficient, right?

One of the first real programs I wrote was a program to display telemetry data from a CAN bus. I was on the solar car team at uni, and we wanted to be able to view the data from the various systems live during the race. The CAN network was connected to a CAN-ethernet converter, which sent UDP packets over a wireless ethernet link to our lead car. I had no experience with networking, or UDP or CAN at all, but I had some documentation and a lot of free time, so I got to work.

Each device on the CAN network had a bit mask to identify it. For example, the bit mask for the motor controller might have been 0x1200. This meant that any packet starting with 0x12 belonged to the motor controller. For example, 0x1201 was one type of message, and 0x1202 another type, but both belonged to the motor controller.

There was specific logic for each device on the network, so you needed to first figure out which device owned a packet using the bit mask, then apply the relevant logic to decode the packet.

Looking back, I realise the correct way to approach this would be to have a list of bit masks:


<span style="color:#323232;">0x1200
</span><span style="color:#323232;">0x1300
</span><span style="color:#323232;">0x1400
</span>

Then simply bitwise & any incoming packet with 0xff00, and lookup the result in the list of bit masks.

Not knowing better however, what I actually did was create a giant dictionary of every possible packet value, so I could lookup any packet and determine which system it came from. This was so repetitive that I had to make use of my newfound super-power – vim macros – to complete the 8000 line dictionary…

Excerpt from real code below:


<span style="color:#323232;">{
</span><span style="color:#323232;">    0x102:
</span><span style="color:#323232;">    {
</span><span style="color:#323232;">        'name':             'SHUNT_CMU_STATUS_TEMPERATURE_AND_VOLTAGE_1_2',
</span><span style="color:#323232;">        'data':
</span><span style="color:#323232;">        [
</span><span style="color:#323232;">            'cell_0_voltage',
</span><span style="color:#323232;">            'cell_1_voltage',
</span><span style="color:#323232;">            'cell_2_voltage',
</span><span style="color:#323232;">            'cell_3_voltage',
</span><span style="color:#323232;">        ],
</span><span style="color:#323232;">        'unpack_string':    'intle:16, intle:16, intle:16, intle:16'
</span><span style="color:#323232;">    },
</span><span style="color:#323232;">
</span><span style="color:#323232;">    0x103:
</span><span style="color:#323232;">    {
</span><span style="color:#323232;">        'name':             'SHUNT_CMU_STATUS_TEMPERATURE_AND_VOLTAGE_1_3',
</span><span style="color:#323232;">        'data':
</span><span style="color:#323232;">        [
</span><span style="color:#323232;">            'cell_4_voltage',
</span><span style="color:#323232;">            'cell_5_voltage',
</span><span style="color:#323232;">            'cell_6_voltage',
</span><span style="color:#323232;">            'cell_7_voltage',
</span><span style="color:#323232;">        ],
</span><span style="color:#323232;">        'unpack_string':    'intle:16, intle:16, intle:16, intle:16'
</span><span style="color:#323232;">    },
</span><span style="color:#323232;">}
</span>
Karyoplasma ,

If it works, it works. Let your successor worry about maintainabilty.

julianh , in Javascript is the most popular scripting language in use today

Don’t forget jsfuck

AlexWIWA , in Single?

Just wait for them to buy programming socks

a_statistician ,
@a_statistician@programming.dev avatar

What’s wrong with programming socks?

AlexWIWA ,

Nothing, he’ll just finally have women to date in his CS classes.

pileghoff , in Single?

First semester of my cs degree, it was around 50/50. After 3 semesters very few women were left. Spoiler: it was not because they could not handle the courses.

Kecessa ,

It was another time, but the first field my mother went into was IT. She dropped her punch cards on her way to the computer and had to explain to the teacher that she would need time to put them back in order. His reaction?

“Women have no business in my class, go do the nursing program instead.”

6daemonbag ,

The takeover of a what was once a female-dominated sector was in full swing at that point. A damn shame. Did she stick it out?

Kecessa ,

Nah, but she still ended up as a manager in a tech company so she won in the end 😂

thebardingreen ,
@thebardingreen@lemmy.starlightkel.xyz avatar

I had a shitty old (late 60s) boss in 2008 who once interviewed a female engineer straight out of college.

Most interviews he gave took like 25-30 minutes. He spent an hour and a half alone in the conference room with this young woman.

After she left he said something to the team like “Sure wouldn’t mind seeing her around the office every day eh? We’re not hiring her of course. Women don’t have the head for this work.”

This same guy had me block all news sites except Fox News (I was the IT director). He was fine with his employees reading the news as long as it was Fox (I ended up teaching a couple of my coworkers how to use proxies).

ShaggyDemiurge , in Single?
@ShaggyDemiurge@lemmy.blahaj.zone avatar

Wait for some of them to transition

Kecessa ,

Be a m2w trans that wants to study CS

Study CS first

Transition when done with school

Sexism from fellow students avoided 👍

Nobug404 , in if else if else if else
philm , in when you see this posture you know the code gonna be fire

And yet, he’s using the mouse and an Apple keyboard.

Where’s mech-vim-hacker-typer-power?

dept ,

he’s at an apple store

TheSaneWriter , in B-bug? What bug?
@TheSaneWriter@lemmy.thesanewriter.com avatar

At least refactoring the code can make the bug easier to find. What I hate is when I spend hours looking for a bug because I missed a single line in some documentation and misunderstood how something in the project worked, that always hurts.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines