Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "looping"
-
I hired a woman for senior quality assurance two weeks ago. Impressive resume, great interview, but I was met with some pseudo-sexist puzzled looks in the dev team.
Meeting today. Boss: "Why is the database cluster not working properly?"
Team devs: "We've tried diagnosing the problem, but we can't really find it. It keeps being under high load."
New QA: "It might have something to do with the way you developers write queries".
She pulls up a bunch of code examples with dozens of joins and orderings on unindexed columns, explains that you shouldn't call queries from within looping constructs, that it's smart to limit the data with constraints and aggregations, hints at where to actually place indexes, how not to drag the whole DB to the frontend and process it in VueJS, etc...
New QA: "I've already put the tasks for refactoring the queries in Asana"
I'm grinning, because finally... finally I'm not alone in my crusade anymore.
Boss: "Yeah but that's just that code quality nonsense Bittersweet always keeps nagging about. Why is the database not working? Can't we just add more thingies to the cluster? That would be easier than rewriting the code, right?"
Dev team: "Yes... yes. We could try a few more of these aws rds db.m4.10xlarge thingies. That will solve it."
QA looks pissed off, stands up: "No. These queries... they touch the database in so many places, and so violently, that it has to go to therapy. That's why it's down. It just can't take the abuse anymore. You could add more little brothers and sisters to the equation, but damn that would be cruel right? Not to mention that therapy isn't exactly cheap!"
Dev team looks annoyed at me. My boss looks even more annoyed at me. "You hired this one?"
I keep grinning, and I nod.
"I might have offered her a permanent contract"45 -
Fuck you, devs who quote Knuth:
"Premature optimization is the root of all evil"
I agree with the spirit of the quote. I agree that long-winded arguments comparing microsecond differences in performance between looping or matching constructs in a language syntax is almost always nonsense. Slightly slower code can even be preferable if it's significantly clearer, safer and easier to maintain.
But, two fucking points need to be made to you lazy quickfix hipsters trying to sell your undercooked spaghetti code as "al dente", just fucking admit that you had no clue what you were doing.
So here we go:
1. If you write neat correct code in one go, you don't need to spend time to optimize it. Takes time to learn the right patterns, but will save you time during the rest of your career.
2. If you quote Knuth, at least provide the context: "We should forget about small efficiencies, say about 97% of the time [...] Yet we should not pass up our opportunities in that critical 3%"
YES THAT CRITICAL 3% IS WHERE YOU MESSED UP.
I'll forgive you for disgorging your codevomit into this silly PR.
BUT YOU'RE QUOTING KNUTH IN YOUR DEFENSE?
Premature optimization is the root of all evil... 6300 SQL queries to show a little aggregate graph on the dashboard... HE WOULD FUCKING SLAP YOUR KEYBOARD IN HALF IN YOUR FACE.3 -
C=consultant
M=Me
D=my Dumb boss
M: so how are you guys planning to implement the block all accounts feature?
C: oh it should be easy! We will just loop over every account and lock it!
M: what about implementing a flag that just blocks anyone from accessing the site till further notice?
C: what? I’m sure it’ll work. Just need a list of all accounts, we don’t need anything fancy!
M: what happens when we want to revert back to the pre-block state?
C: oh, so we will just unblock everybody
M: even people who were previously blocked for good reasons?
C: i guess so, unless you think otherwise
M: we r….
D: listen! We just need to be able to block all accounts, who cares about this details! So long as we block all accounts! We need this nuclear option in case something bad happens…
M: but what about when that bad thing passes and…
D: when it passes it passes who cares!
Arghhh so much rage here… like first at the stupid engineering design of looping over all of the accounts instead of using a simple flag. Like 1 http call (from one microservice to another) is a lot better than O(n)… not to mention, we won’t have to deal with failures and retries.
And second for my boss being a dumbass… ok you deal with being to afraid to unblock people after we used this “genius nuclear option”!6 -
This was WAY back in my first job as a programmer where I was working on a custom built CMS that we took over from another dev shop. So a standard feature was of course pagination for a section that had well over 400,000 records. The client would always complain about this section always being very slow to load. My boss at that job would tell me to not look at the problem as it wasn't a part of the scope.
But being a young enthusiastic programmer, I decided to delve into the problem anyway. What I came to discover was that the pagination was simply doing a select all 400,000 records, and then looping through the entire dataset until it got to the slice it needed to display.
So I fixed the pagination and page loads went from around 1 min to only a few seconds. I felt pretty proud about that. But I later got told off by my boss as he now can't bill for that fix. Personally I didn't care since I learned a bit about SQL pagination, and just how terrible some developers can be.5 -
A few years back I worked at a company as their front-end web developer with one other guy who was their "back-end" developer. PHP and MySQL specifically. He was eventually fired and I took over both development roles. When I got around to seeing his source code and the way he had created the databases, I immediately saw why he was fired. This guy did not understand the concept of loops. Instead of separating out tags and categories with a split / loop, he set up database tables for EVERY. SINGLE. TAG.
i.e. tag_1, tag_2, tag_3, etc. And then to top ot off, instead of looping through the tables, he set up huge conditioks for EVER.LY. SINGLE. TAG.
i.e. if(tag_1) else(tag_2) else(tag_3) etc.
That fucking guy...6 -
TLDR: Skills and background or dedication for becoming a good programmer?
So I almost finished the bootcamp on my company, there is only 2 people. Me and another guy who is from math major. He wanted to learn programming so he applied for the job. He doen’t know sql, any backend language, and not even html or css when he joined. The only thing he knew is for looping and if condition logic. He survived 1 months or so by learning a lot here. C#, .net mvc, sql, decent css and html. I believe he worked hard by learning it by himself. But the company he can’t continue anymore. I doesn’t know the reason but probably because he is seen as not good enough. Sure he is kinda slow when adding some feature to our small project but we need to find how to do it by ourself mostly. Now I’m alone with another few weeks to continue4 -
.... And it appears my Atom has Entered the Matrix. Full time.
In other news, I successfully completed the E-Commerce App I was working on, even though that Stripe Verification was a ball ache and the bane of the entire project giving me a stupid bug in jQuery whereby it was infinite looping over adding the token and not actually submitting the card charge. Somehow changing my button from using an id to using a class fixed my problem :/ (# -> .)11 -
!rant
Question time for you very few Salesforce devs out there, yea I know there’s some.
Seeing as Google is not my friend today, I’m trying to get SOQL to return null valued fields back to a rest api, something this hunk of shit won’t do, and short of looping back through all the records and injecting these fields back in, I’m at a loss... any advise is welcome 🤯 -
By constantly fucking around with things that interest me. If a topic fascinates me i will either lool for shit around youtube, read proper documentacion or buy specialized books for it.
Most recently it has been compiler design. I wanna write my own language, for testing and learning more than anything.
I dunno, it keeps shit fun and interesting. Now, much of that shit ain't applied to what I do in web. But it does help to keep the mind fresh as well as giving me the chance to eventually invent my own language. Write a large system with it, use it at the institution and have them pay me obscene ammounts of money to maintain it.
It will be like VB6 or VbScript, but with {}s, immutable values by default and no looping, cuz I am evil AF -
Been using linux for 10 months now and finally figured how to write looping statements in terminal itself instead of writing a script for that .. Life just became simpler..3
-
Ladies and gents, it was a 🍺 day, today.
I spent more hours than I care to say today tracking down an issue in our web workflow, even looping in our only web dev to help me debug it from his side. There ended up being multiple bugs found, but the most annoying of them was that the json data being pulled back was truncated because a certain someone, in their migration script, set their varchar variable to a size of 1000 and then proceeded to store a json string that was 2800+ characters in length.
C'mon man!
I got nothing productive done today. Hate, hate, hate days like this!
Beer me.3 -
The programming things I've seen in code of my uni mates..
Once seen, cannot be unseen.
- 40 if's in 10 lines of code (including one-liners) for a mineswepper game
- looping through a table of a known size using while loop and an 'i' variable
- copying same line of code 70 times but with different arguments, rather than making a for loop (literally counting down from 70 to 0)
- while loop that divides float by 2 until it's n < 1 to see if the number is even (as if it would even work)
..future engineers
PS. What are the things you've been disgusted by while in uni? I'm talking about code of your collegues specifically, I'm also attaching code of my friend that he sent me to "debug", I've replaced it with simple formula and a 2D distance math, about 4 lines of code.6 -
Kids: I'll tell mom, she'll scold you.
Adults: Looping in my team lead in mail chain
Source: Twitter1 -
hey devs, quick question:
does rust support branchless conditionnals and jump tables, and if yes where to look for syntax?
i found no example for branchless so far and jump tables are scary in rust (and i need a library to use them, it seems).
inb4 "why in the hell/ what possible use those have?!":
i use branchless to make a looping array and jump tables whenever there's more than 4 if statements with equal probability, and the deciding factor is a numeric value, so quite often.27 -
I always confuse `for..in` with `for..of` and have to look up their respective meaning. Again.
It drives me crazy.
Do you have any mnemonic on this? How do you remember the difference?
(Now, as in this very moment, I know that for..in is for looping over keys of an object and for..of for looping over iterators. But tomorrow I will have forgotten it again.)10 -
This is probably a standard pattern/algorithm, but I feel pretty good about myself figuring this out.
I was doing a programming challenge and found myself with 2 lists of integer points (x,y). I needed to see where the points converged and identify those locations. Of course I started with a brute force approach and did nested loops to find these locations. This was taking WAY TOO LONG. These lists were 200K each. So checking with naive looping is 200K * 200K operations. Which is a lot.
Then I thought, well I am checking equality, so I will create a third map. The index to the map will be the point, and the data will be an integer. I then go through each list once incrementing the integer for each point that exists in each respective list. Any point with a value greater than 1 is a point convergence.
Like I said, this has got to be a standard thing, so can someone tell me what algorithm this is? I am not sure how to search for this.
I am fuzzy on complexity notation but I think the complexity started at n^2 and was reduced to n. Each list is cycled over once.4 -
Code for Matrix Rain Using HTML
<!DOCTYPE html>
<html>
<head>
<title>Matrix Rain</title>
<style>
* {margin: 0; padding: 0;}
body {background: black;}
canvas {display: block;}
</style>
</head>
<body>
<canvas id="c"></canvas>
</body>
<script>
var c = document.getElementById("c");
var ctx = c.getContext("2d");
//making the canvas full screen
c.height = window.innerHeight;
c.width = window.innerWidth;
//english characters
var english = "1001010101110101010101010010101000101011101111010101010110101010101010101110000101";
//converting the string into an array of single characters
english = english.split("");
var font_size = 15;
var columns = c.width/font_size; //number of columns for the rain
//an array of drops - one per column
var drops = [];
//x below is the x coordinate
//1 = y co-ordinate of the drop(same for every drop initially)
for(var x = 0; x < columns; x++)
drops[x] = 1;
//drawing the characters
function draw()
{
//Black BG for the canvas
//translucent BG to show trail
ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.fillStyle = "#0F0"; //green text
ctx.font = font_size + "px arial";
//looping over drops
for(var i = 0; i < drops.length; i++)
{
//a random chinese character to print
var text = english[Math.floor(Math.random()*english.length)];
//x = i*font_size, y = value of drops[i]*font_size
ctx.fillText(text, i*font_size, drops[i]*font_size);
//sending the drop back to the top randomly after it has crossed the screen
//adding a randomness to the reset to make the drops scattered on the Y axis
if(drops[i]*font_size > c.height && Math.random() > 0.975)
drops[i] = 0;
//incrementing Y coordinate
drops[i]++;
}
}
setInterval(draw, 33);
</script>
<body>
</html>1 -
Til that Node 10 has `for await ... in`. Basically looping async iterators. This changes everything!5
-
Instead of looping through your entire project, just recursively calling main() to restart every time it would otherwise end
-
Hi so I'm learning python in my spare time and I'm in a national competition. I've been told that programming is something my college has always lacked in and in the competition they fortunately use python throughout the problems. I have some example problems used in the last year competition (it was publicly released) and I'm going through them to get an idea of the problems we/I will face. Now I'm still learning python but I understand some of the code at hand. However I still need a little bit of help to understand some of it which will also help me get to a resolution.
Some of the questions I have are:
1. What exactly is the ordinal? I've done some research and I have a small idea but I couldn't find anything to really fill me in and explain how to use it, well in python at least. I saw an example for Pascal but that didn't do much.
2. What is the sys.argv? "The list if command line arguments passed to a python script". I'm not quite understanding that.
3. I know for is used for looping and I know an example say "for a in range(10):" but I'm not understanding the for c in password:
4. Where does the 1000 come from in the builder += 1000.
5. What does the 83 represent after ord(password[1])
6. I know the if statement is saying if this then do this so if __name__ == "__main__":
main()
It's saying call in the function main but where does the name and main come in that part?
Here is the image:
Thank you for your responses in advanced!
One person doesn't have to answer all. Time is precious I understand.8 -
I'm learning Rust as a case study for my own programming language. It's funny how many approaches exist to the humble loop.
- In classic procedural languages, a loop's job is to repeat actions, and as such it provides a multitude of tools to control this repetition.
- In all languages with iterators, a for-in loop is a construct that does something with every element of a collection. In languages with both iterators and generator functions, this can even be used to define a sequence in terms of another.
- In Rust, a loop is an expression that obtains its value through repeated execution. It can also be used like a classic loop, of course, but this is the interesting part.
- My little language is a functional language, so "loop" is the Y combinator. To loop means to define the value of an expression in terms of itself. It's the only looping construct, gets special treatment from the type checker and it's also used in recursive type definitions. -
Soooo i recently wanted to install FreeBSD on one of my servers. I configured the raidcard and booted the installer. Installation goes normaly. Sever restarts and begins looping. After tearing apart every firmware on this machine and going to bed, a thought was crossing my mind: What if the UEFI doesnt boot the disk? What if the RAID card does? What if the RAID card cannot boot GPT tables?
Next thing iin the morning, i reinstall freebsd with MBR. And it works (after my NICs stopped working, so i had tp reinstall another time). I STILL GOT IT! That wasnt the problem we all fear to cannot solve anymore ^^5 -
when your team member writes 30 lines of looping code which is really just a 1-line filter & map call.
-
Okay so update/JS pt2
This is just me throwing my thoughts down and some questions
I've been practicing arrays/objects and loops more and I'm getting more understanding it helps that you can do them both at the same time. But like I need more looping techniques (if that makes sense) like instead of always using for(let i = 0; i <= x.length; i++) and I havent completely learned how or when I use for(x in y)
Questions.
• what's the difference between class objects and objects that look like a python dictionary
• when should I use classes over the other kind of classes
• any good resources and projects I can practice with loops cause I'm kind of running dry on ideas
and I dont wanna google cause I barely already have no social interaction2 -
Spent most of the day at work debugging a script which imports client data from their old system into our system. Someone made a change to a for loop which was looping through a period length by days, doing whatever it needed to do for each day. Unfortunately they changed the increment value from 1 day to 86400 days... probably thinking they were dealing with seconds not days. A day well spent.1
-
What is your goto style of music? What is your empowering 'lets do this' or " I'm in the zone" thing?
For me I have a collection of various genres of music I've collected over time and I slap together several songs at the days start and get going.
Usually I end up looping a single high energy song all day (rock usually. Especially older rock)13 -
(a bit late for wk73 but I wanted to post this anyway)
Back in my first year of university, we had to write a relatively simple (though it looked super complicated back then) C++ console application. I don't know what it's called, but it's that game where the computer generates a random 4 digit code and you have to try to guess what it is. Every time you try, it will tell you which digits are correct, which would be correct if they were in a different position and which are outright wrong.
Anyway, the program had a main menu with a help option that would output a short guide on how to play the game. Instead of hard coding it into the source code, the "guide" had go be written in a separate text file and then read and dumped to the screen when necessary.
Here came my great idea on how to read files. Instead of looping through the file until I reached the end, I counted the number of lines my text file had and wrote some gem of a piece of code like this:
for (int i = 0; i<11; i++){
line = file.readline();
cout << line << endl;
}
My teacher obviously took points off for doing such a stupid thing, and I remember complaining A LOT about it. I argued that 11 was a constant because I didn't plan on changing the text file, and that the teacher had no right to take points off for only reading 11 lines because the file only had 11 lines, so it was read in full.
Goddammit, what an innocent little brat I was. I'm glad my first programming teachers were good enough to stay firm and teach me how to do things the right way, even if it's the hard way. -
Way too long story short: Needed to figure out how to use jQuery to update a table that had no classes or IDs to help you tell what's inside it. Worked out a looping structure to read the contents of the cell with the dependent data in each row, and then update the cell that needed changing depending on the value of the first cell.
Minified the solution and dropped it into the console. Worked exactly right on the first try. -
My team feels like a bureaucracy multiple decision makers looping to one another causing confusion to developers.
-
Oh china, you always know how to snap me out of long stints of mundane and/or annoying, chore-esq work.
//...and letting me excuse a 10min, otherwise purely wrong procrastination down a current political rabbit hole
I gotta say, at least in china they are bold enough to put their image and identity on whatever they make... but in that 'im selling pseudo-sex, not because im sexy--just the opposite, so you know I relate' way.
Side note: i got an automated spam call survey yesterday*... it ot got to the 1st (of claimed 3) question.. which had a surprising amount of actual reiterations before looping... it was determined to get opinions(and totally incept the lemmings, soccer moms and politically ignorant into their stance, plus intense rage/disgust/dreams of standing on a soap box and fighting about this new issue they were totally unaware of.)... about this actively serving, politician's demand that china sell tiktok or totally stop allowing any operations/use on american soil... because of the heavily implied heinous nature of controlling and twisting society via media to it's explicitly declared communism... even directly called china, as a whole, communists, with impressive dramatics (and i coached public speaking hs and college kids then over a decade of business consulting, typically involving coaching vocals and implicit vocab)
I actually listened to it because it's what a typical subject, brought out of the koolaid fog, would view as ridiculously ironic(assuming they knew the actual, and therefore inherently ironic, def if irony... most dont. It's disturbing)... but it you have decent common sense, and dont emotionally view your entirety as wrong/broken/needing to be fixed in a cult-like manner, it's the oposite of irony. History of/and politics pull this crap all the time. It still works.
It reminds me of how my moniker, awesomeest, came about. In 3rd grade i realised that even adults, knowing they were chatting with an 8yr old, even if they knew/used the correct spelling of a, less common, term... if i misspelled it as if i thought it was right, theyd actually change their spelling to match (in perpetuity) albeit my vocab was easily high school level by then...likely at least in part to my flawless(aka blind/ignorant) demeanor of confidence that whatever i said/thought was totally correct, as a matter of fact. Not like the insecure ppl trying to prove something
I used to find it so comical... now it's just sad.
This bs automated political spam/manipulation is the modern version of i remember of kids farting in the late 90s... the culprit quickly accusing someone else of their offense, but even extra immature kids 25+ yrs ago figured that out... and even made the retort a catchy rhyme..."the one who smelt it, dealt it"
*i basically programmed in a counter attack/something akin to immature passive aggressive ' who"s really the one wasting the other's time and resources now?!? Ha!' ...odd numbers automatically go into a sort of echo chamber instead of ringing, with a manual escape to actually ringing/calling prompt built in.
I can listen in at any time without it having any effecf/sound too.
I'm curious if anyone participates in these minor acts of terrorism to complete an unrequested, intrusive, and human-less format of a proclaimed opinion poll? And if you do, are you honest? Why do you do it?
Annoyance at spam aside... the real victim I mentally mourn, and view it's method of demise akin to a cardinal sin (assuming religion...blah blah)... is the data! I <3 data... good, unobscured, not contrived, simple, pure, raw data... killed before its birth :'(5 -
So I was playing around with JS inside of QML (Qt). I wanted to turn a number into a string and then modify individual chars based on certain criteria. Then I would convert back to a number. Should be simple right? Well JS would not let me write to the indexed element of the string. What the actual fuck? I need to drop to C++ to do actual string manipulation? I ended up looping the string and turning it into an array and then a join back to a string. There is probably a better way to do this in a more modern version of JS, but I am now starting to see why JS is a pariah on here. It has some quirks that make you question your devlife choices.
What was I working on? Some stupid crop circle thingy. I was trying to use the QML Canvas to draw some "simple" crop circles. So I started with this crop circle:
https://plus.maths.org/content/...
The result ended up being kind of a swirling crop circle thing. The static image was too boring:
https://imgur.com/gallery/900hogf
And yes, I was too lazy/cheap to license the screen capture program.7 -
Noticed that I'm looping too much on same thoughts, need to write them down. Can you advice some good platform or app which I could use for journaling/diary writing? Having a good search function is also a must! I already tried penzu.com but their search functionality sucks.6
-
If I'm going to compare my love life to a looping statement, my do while is about to terminate. :(4
-
I've said it before and I'll say it again: I believe in theoretical study prior to proof of concept.
At least for me, it takes me a 100 times more time to make a proof of concept the 'quick and easy' way rather than properly studying the theoretical knowledge and then applying it.
For example, it took me one and a half months to build a small website in ReactJS without much prior knowledge. It took me exactly one day performing the same task when I properly had studied all its internals and theoretical knowledge before I started.
If I know what I'm doing, I can easily create; if I don't, then I'm just messing around, looping myself into problems ad infinitum.
Teach a man to fish..2 -
Did 1 leetcode today
https://leetcode.com/problems/...
Able to run the algo on paper and wrote down the javascript, not able to pass some test cases. so need to copy the answer.
My idea is similar, but the answer is much better. The idea is similar to tracking max number, but this time we have max1, max2, max3 (max1 is largest)
init all of them to null.
looping number array, if number is in maxs, skip. If there number > max1, we update all max1-3
if number > max2, update max2-3
then number > max3, update max3
last return statement is like this: return max3 == null ? max1 : max3;