Details
Joined devRant on 4/26/2018
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
-
:headache:
Reading a JS book. Came across the following classic race condition problem that reminds me of my college lessons on async programming and threading. It sure is a headache.
Thanking A.I. for explaining it to me further, because I was thinking that the value kept being updated with each fileName once resolved, but no:
async function fileSizes(files) {
let list = "";
await Promise.all(files.map(async fileName => {
list += fileName + ": " + (await textFile(fileName)).length + "\n";
}));
return list;
}
Problem:
1. list starts as an empty string.
2. For each fileName, you create an async function (inside map) that does:
list += fileName + ": " + (await textFile(fileName)).length + "\n";
3. Because all the async functions are launched at once (via Promise.all), they all reach their await quickly, and at that moment they all “remember” the same initial value of list (the empty string).
4. Then, whichever async call resolves last will overwrite list with its update. The previous writes get clobbered, since each one applied += to the old snapshot (""), not the already-updated string.
A.I.: Why is this a problem?
The root cause is mutating shared state (list) across async boundaries. Because += is not atomic, each async task doesn’t “see” the other updates — they all start from the same baseline.
Solution:
async function fileSizes(files) {
const lines = await Promise.all(files.map(async fileName => {
const length = (await textFile(fileName)).length;
return fileName + ": " + length;
}));
return lines.join("\n");
}
Each async task just computes its own independent result string. No shared state, no race condition.
Book lesson: computing a new value (though more expensive) is often less error prone than changing existing values (bindings in this case).
College lesson: remember that operations on a computer are not atomic. You always have things like the ALU, the registers and the values in between. Oh great, now I am reminded of atomicity in database transactions. :barfs: lol
Useful lessons. This is why Computer Science fundamentals are important. :)7 -
Weird error message from webpage: "Hello, my name is Inigo Montoya. You killed my webpage. Prepare to die".
It's a Princess Bride parody...
Developers get creative (or bored) these days with error messages.. Yes, one of those again.5 -
JavaScript keeps surprising me, or I'm just rushing. lol
class Group {
#group;
constructor(){
this.group = [];
return this.group;
}
add(item) {
// only if it isn't already a member
// value can be part of set only once
if(!this.has(item)) {
group.push(item);
}
}
has(item){
// return boolean: item member of group
for(let i=0; i<group.length; i++) {
if(group[i] === item) {
return true;
}
}
return false;
}
let group = new Group();
group.add(1);
console.log(group);
Error: group.add() is not a function
Why is group.add() not a function?
A.I. analysis:
1. Private field vs public field:
A private field #group can only be accessed as this.#group. But in the constructor, I wrote:
this.group = [];
This creates a new public field, unrelated to #group.
2. Returning from constructor:
return this.group;
In JavaScript, a constructor automatically returns this, which is the instance of the class. Returning this.group replaces the instance with the array. That’s why after new Group(), your variable group is just an array, not an instance of Group. Arrays don’t have the add method — hence the error.
3. Referencing group inside methods:
group.push(item);
Here group is not defined. You probably meant this.group (or this.#group if using the private field).
Note to self: in the magic of computer science, you must be precise. If I loosely define the black box, the result will have a chance of producing anomalies.. kind of like reality. lol8 -
I'm sitting here realizing that Software Development and Computer Science in general, heck, STEM, is the most difficult skillset to endure because of the stress we go through as well when dealing with the workplace, especially the workplace.
I looked up how hard Computer Science is versus Advanced Physics and it is rated 40 vs. 80, the latter being doubly difficult. Now I got to thinking: Could it be us as developers are experiencing near-80 difficulty because of the stress we are put through to rush through deliveries at work? Maybe it's a 50. Hm, hm.
What a delight it must be (no sarcasm) to be able to research and perfect something for 20 years without people breathing down your neck about deadlines.. aaaahhh... lol.1 -
Story:
Useful lesson I learned in a JavaScript book:
"Classes are abstract data types in the sense that they are a layer around the complexity (encapsulation). Their singular nature allows them to be reused without being rewritten everywhere.
A good analogy is thinking of classes as appliances; the complex circuitry and components that an appliance comprises of are made by different people than the abstract shell around these components, of which (another) team only needs to know which buttons to access which parts.
A class abstracts away the internal complexity (components) and only exposes a public interface (the buttons) that the user (yet another group, comparable to the consumer of the class) is going to use."
It reminds me of how Google uses the Facade pattern to only expose the search box and the button as its public interface and all the complex architecture is hidden away.
This helped clarify classes better for me.5 -
!rant Lovely quote:
“There are two ways of constructing a software design: One
way is to make it so simple that there are obviously no
deficiencies, and the other way is to make it so complicated
that there are no obvious deficiencies.”
—C.A.R. Hoare, 1980 ACM Turing Award Lecture2 -
!dev Isn't it hilarious how some companies 'try' to look professional by dumping a bunch of stock images to present their brand? For example, a guy touching a holoscreen, or a bunch of overly stock happy corporate drones smiling and 'working' together in a 'meeting'.
I mean, it's sad. lol8 -
"Block scope in console REPL:
Each line you type in the console is evaluated in a separate, temporary scope. This sometimes makes let and const behave differently than if you wrote the same code in a <script>."
Interesting... I didn't know that. lol -
https://stackoverflow.com/questions...
JavaScript sure is a pain in the butt when it also throws errors depending if you are in a REPL or not.
Hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.3 -
DevRant is slow today.
I came in like a laaaaaaaaaaaaaaaaagging baaaaaaaaaaall, I never hit so haaaaaard in loooooooooove
lmao.3 -
I found a simple code example in a book teaching programming concepts:
let result = 1;
let counter = 0;
while (counter < 10) {
result = result * 2;
counter = counter + 1;
}
console.log(result);
// 1024
...I can't believe I didn't get it right the first time. Yes, the result is 1024 and not 20. For it to result in 20, the statement would have to be:
result = result * counter.
Upon reflection I concluded: An exponent is a multiplication by a multiplication, so... it exponentially grows.
So I ask: how do you develop a second nature for these kind of problems? You studied it? You studied and practiced it? You're awesome at mathematics? It annoys me that my intuition often wrongs me when it comes to mathematics.23 -
Like many of us, tired of hearing the expressions: "infused with A.I.", "powered by A.I.", "augmented with A.I.", "A.I.-first", etc.6
-
Good dev: test suites, documentation, tracking
results: decent coverage, more predictable, more maintainable, saves time and money, accountable to stakeholders, happier team thanks to transparency
environment: matured middle-sized to bigger company who takes things seriously (because they usually have to if they work in a heavily regulated sector)
Bad dev: idgaf attitude, let's just run with it and see what happens flow, go for bare minimum happy path
results: a new bug at every possible situation, mystery bugs, an endlessly-growing backlog where people in the team are so depressed no one cares what ticket to take on, morale goes down crapshoot and so does code
environment: start-ups who want quick wins and make money-based decisions only and whose budget is being guarded by the higher-ups
I've worked with a bad dev before and also with a good dev and I appreciate the difference. lol. Nightmare.16 -
Job-hunting feels like playing Age of Empires; the cities are guarded by the recruiters.
Rogan? Wololoo.6 -
There are still websites that miss the simple, modern UX feature of saving form state. No, it's not 'push a button to apply the filter' anymore, it should be 'tick the box, slide the slider' and the state gets persisted immediately.
Or something else: perform a search, apply filters, and the original search is lost. Tf, man? lol.
This just shows that some places aren't investing.3 -
How do you compete and distinguish yourself as a freelancer from the other super-experienced freelancers? To me it seems almost impossible to get a foot in unless you're a niche expert, and even then.
Say you have 4 years dev experience. How the heck can you match up against someone with 15 years experience or someone with 5 years + several successful client projects? Or someone who's flawless at Full-Stack and you're just a mere beginner?
It seems to me you have to be super strong at selling yourself.6 -
GRAARGHHHHHHHHHHHHH POOHHHHHHHHHHHHH!!!
That's just my frustration with SourceTree.
This is a story all about how my SourceTree got twisted upside down, and I'd like to take a minute to just sit right there and tell you how I pushed my code to my repository on GitHub:
Iiiiiin my SourceTree, born and raised, I checked out my branch, tried to push but SourceTree said: "See ya later!" (denied/authentication failed). Sssoooo I told myself I was not going to use ChatGPT to solve this problem. I was going to use my Medior skillzzzz1!1!1!Oen and so I did solve it, but what a fucking hassle!
First I tried to remove all credentials from SourceTree and from my system, then I tried to add a fine-grained PAT, and finally... someone mentioned on StackOverflow that it was the git version that was oudated. So, SourceTree has an outdated embedded git, even on the latest version. Wtf?! Anyway, so I let it choose system git (which uses the latest git version).
And now it works!
Haaaaaaaaaaaaaaaaaaaaaa.14 -
You are considered a junior developer when you need 'a lot of hand-holding'. Now, I can figure out most things on my own, but how do you distinguish between 'needs too much hand-holding and therefore is a junior' and 'does ok and therefore is a medior'?
For example, I can do well on basic things and getting projects set up, but then I might need more help if errors truly become too cryptic or difficult to solve and I haven't found solutions. A few examples here:
- having messed up the git branches and releases so much that you need someone with a deep knowledge and troubleshooting of git to set the situation straight
- spending a week on trying to figure out why Azure doesn't want to successfully build your super custom build and it takes ages to figure it out because it requires in-depth Docker, linux knowledge and stellar, MIT-level troubleshooting and analytical skills
And so, someone who needs help with these is considered a junior?
How do you really identify a junior? Seems vague.13 -
What is your method of dealing with states in state machines? In programming, we often come across situations where we have to model states in our head as to not get the programming wrong, e.g. in my case right now:
You have a tabular webform that gets filled in.
Requirements:
- When the user is able to search the data for a specific value, it should be a cumulative search (e.g.: search for books with "eng" in the language and then with with "19" in the publishing date)
And so the current pseudocode is:
search(e) {
if(!word) {
set(previousState);
}
const searchdata = previousState.filter((row) => row.indexOf(word) != -1);
// but wait, what if I say: searchdata = searchdata.filter() for cumulative search? Oops, I can't, because it doesn't exist at that moment yet. What if I create another variable?
setState(data: searchdata);
}
Current bug:
- when deleting characters from the search field, it doesn't filter cumulatively; it just filters the data according to the current filter.
It's things like these that get me stuck sometimes.12 -
!rant Writing code in a barebones text editor so that I am forced to think more about my code and debug deeper. Hah! No more fancy IDE's while learning (for now)!13
-
The latest and greatest bullshit at the workplace: when you're asked to be an 'ambassador'. This really just translates to: 'take on more work for free'.
Whenever management approaches you with 'honorable extra role', immediately ask how it's compensated and definitely don't do it for no extra benefits (a raise should be default).
Don't fall into the trap.2 -
!rant https://www.imgopt.com/ (known as smush.it!) is the online image optimization tool of choice.
I came across it when reading one of my React books. I hope it proves useful to people.1