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 - "ifs"
-
DataBase not approved, just use spreadsheet they said...
65487456456 errors later...
Many litres of blood later...
866 brackets just for the closing
528 ifs20 -
You know what I realized we should always say no for demo driven application development.
We should always ask for enough time do a proper development and if its not enough, shouldn’t write a single line.
Because once we deliver a working demo. Its release ready for them because its FUCKING WORKING..
And trying to explain why this is just a demo and cant be put to production is even bigger pain in the ass than saying no in the beginning.
LESSON LEARNED .4 -
Why is the ternary operator such a hated thing? I constantly hear people saying it's less readable, confusing, etc.
I think it's a beautiful, useful, and important operator and I use it constantly wherever readability won't be much affected.
How can you justify a repetitive if/else structure over a ternary, given that you're sure you're not going to put anything else in the ifs?
Whatever happened to DRY?
Whatever happened to KISS?
If those guidelines are what you code by, what's the excuse not to use it?
Because you can't read it as well? Familiarity breeds comprehension and legibility, my dudes.15 -
Manager: I like nested ifs
Dev: They can be difficult to maintain
Manager: No they aren’t I write them all the time!
Dev: Have you ever maintained one?
Manager: No, I don’t do code maintenance. I don’t have time for it.5 -
Worst:
One fine Friday night in early '97 while drinking with my buddies I got a page from work. Called the office to understand what the problem is.
*shit I can't fix this over the phone, and buddy here doesn't have a PC so I can't dial-in via PCAnywhere*
Told told the users "Ok I'll be there in an hour and a half. Stop all the running jobs and start the backup"
*figures I still have 1hr to spare so continues to down fair amounts of O-be-joyful with buddies then hailed a cab to office*
I arrived in office 1.5hrs later (2am) exactly as I predicted and went straight to work. Initial checks confirmed my suspicion of the issue so I wrote the appropriate SQL to get started:
'drop table foobar'
***The specified table (foobar) is not in the database***
I looked at foobar and figured out immediately why I got the error, then corrected the SQL and ran again:
'drop database foobar'
***Database dropped***
*What the FUCK!!! You fucking drunk!!! What did you fucking do? What if I disappear to another country, work as a waiter or something*
After a few moments of panic and a good deal of 'What ifs' I calmed down, looked to the users and made up some bullshit "Some of the indexes are corrupted, we need to restore from the backup"
Best:
I wrote most of my '94 midterm project during weekends where me and my buddies were drunk
https://devrant.com/rants/783197/...2 -
One day, this ex-boss of mine dropped the following bomb:
“Stop using switch statements, the switch statement is archaic.”
The if statement should be even more archaic, right? So, should we stop using ifs as well?12 -
I just love refactoring :) that feeling when an agonic 50loc method with ifs, loops, streams, other shit shrinks down to 3 lines with descriptive and SRP-compliant method calls.. When you can actually read code as a nicely written story. When there are no rubbish comments, cryptic variables and no overly complex if-else skyscrapers jamming all the logic in one conditional chain. When all the abstractions are designed so nicely and design patterns applied so perfectly that extending either of the components is as easy as a walk in a park.
When everything is nice and neat. Only then can I sleep well and enjoy the autumn :)
just some random thoughts after today's coding session :)5 -
Having to review an offshore C++ codebase made in Romania that the company I worked for they bought to control a wifi module on a complex RF mobile tech device that I can't legally give more details on.
If I could legally post this masterpiece, or should I say masterpiece-of-shit, all of you C++ dev would instantly get AIDS and all the existing types of cancer upon browsing it for 2 minutes.
It's laughably bad and unmaintainable. One of my colleague called it "the perfect example of human obfuscation" and it fits perfectly.
Think of a 100k LoC main function with nested loops and ifs with random sleep values, 1000 values of hardcoded 32 bits arrays declared globally in the first 10k lines for unknown reasons. Comments in Romanian mixed with english. Somehow, this shit works by some miracle.
The worst intern you can think of, while being piss drunk, could do better and it's no joke.5 -
Hello everyone 👋
I see people blaming the developers when you see a crappy software product , saying that they have done a bad job.
But even it could be true also it could be the product managers who didn’t give enough time todo what needs to be done or project scope is too big for the persons knowledge.
I’ve worked in a company where deadlines were so tight I didn’t have enough time to proper UI and Testing. I used to be only developer who has someone experience and I had to train the interns as well. I am also to blame to joining such company but in desperate times takes desperate measures.
And now when i’m leaving the company and I have spend 2 years of my life for apps that I’m not proud of.
Just rant. Please feel free to give ur thoughts2 -
Refactoring nested ifs.
I'm not a pro but I despise working with nested ifs. It's hard to debug and read.
If you cant chunk the if using method, i think you can use ifs like this:
If(){return}
If() {return}
Not like this:
If() {
If() {
If() {
}
}
}
😠😠😤🙅😢8 -
Is it just me who sees this? JS development in a somewhat more complex setting (like vue-storefront) is just a horrible mess.
I have 10+ experience in java, c# and python, and I've never needed more than a a few hours to get into a new codebase, understanding the overall system, being able to guess where to fix a given problem.
But with JS (and also TS for that matter) I'm at my limits. Most of the files look like they don't do anything. There seems to be no structure, both from a file system point of view, nor from a code point of view.
It start with little things like 300 char long lines including various lambdas, closures and ifs with useless variables names, over overly generic and minified method/function names to inconsistent naming of files, classes and basically everything else.
I used to just set a breakpoint somewhere in my code (or in a compiled dependency) wait this it is being hit and go back and forth to learn how the system state changes.
This seems to be highly limited in JS. I didn't find the one way to just being able to debug, everything that is. There are weird things like transpilers, compiler, minifiers, bablers and what not else. There is an error? Go f... yourself ...
And what do I find as the number one tipp all across the internet? Console.log?? are you kidding me, sure just tell me, your kidding me right?
If I would have to describe the JS world in one word, I would use "inconsistency". It's all just a pain in the ass.
I remember when I switcher from VisualStudio/C# to Eclipse/Java I felt like traveling back in time for about 10 years. Everyting seemd so ... old-schoolish, buggy, weird.
When I now switch from java to JS it makes me feel the same way. It's all so highly unproductive, inconsistent, undeterministic, cobbled together.
For one inconveinience the JS communinity seems to like to build huge shitloads of stuff around it, instead of fixing the obvious. And noone seems to see that.
It's like they are all blinded somehow. Currently I'm also trying to implement a small react app based on react-admin. The simplest things to develop and debug are a nightmare. There is so much boilerplate that to write that most people in the internet just keep copying stuff, without even trying to understand what it actually does.
I've always been a guy that tries to understand what the fuck this code actuall does. And for most of the parts I just thing, that the stuff there is useless or could be done in a way more readable way. But instead, all the devs out there just seem to chose the "copy and fix somehow-ish" way.
I'm all in for component-izing stuff. I like encapsulation, I'm a OOP guy by heart. But what react and similar frameworks do is just insane. It's just not right (for some part).
Especially when you have to remember so much stuff that is just mechanics/boilerplate without having any actual "business logical function".
People always say java is so verbose. I don't think it is, there is so few syntax that it almost reads like a prose story. When I look at JS and TS instead, I'm overwhelmed by all the syntax, almost wondering every second line, what the actual fuck this could mean. The boilerplate/logic ration seems way to off ..
So it really makes me wonder, if all you JS devs out there are just so used to that stuff, that you cannot imagine how it could be done better? I still remember my C# days, but I admin that I just got used to java. So I can somehow understand that all. But JS is just another few levels less deeper.
But maybe I'm just lazy and too old ...4 -
I had a manager who scolded me in me in public on a non-IT floor because I used child classes and overloading of methods which "is too hard to read". Instead use "lots of ifs and else's". This is the guy that had a JSP so large (be cause he had so many ifs) that it couldn't be compiled even on a server.
The best karma happened a few months later. I was looking for a new job (wonder why?) and was very deep in the interview process - like round 5- of company A. I got talking to this jackass, who had no idea I was interviewing, said "yeah I applied to company A once. Couldn't get past the first round. Great benefits, though.". Me getting the job a week later was the best thing ever. -
Who the fuck writes a 200 line method with 52 if/else statements, 3 try-catches, 6 loops and only 1 comment saying //Array of system records. No dipshit I thought that was a Fucking interface. What happened to the whole keep it simple notion?!5
-
TL;DR you suck, I suck and everybody sucks, deal with it....
------------------------------------
Let me let off some steam, since I've had enough of people hating on languages "just because"
Every language has it's drawbacks and quirks, BUT they have their strengths also. Saying "I hate {language}" is just you being and ignorant prick and probably your head is so far up your ass that you look like an ass hat. With that being said, every language is either good or bad depending on the developer writing in it. Let's give you an example:
If I ware to give you a brick and ask you to put a nail in a plank, can you do it? Yes, it will be easier if you do it with a hammer, but you have a brick, so hammer is out of the question. If you hit your thumb while doing it... well... sorry, but it is not the bricks fault - it is YOU!
JavaScript, yes it has a whole lot of problems, but it works, you can do a ton of stuff and does a good job at that, it is evolving through node and typescript (and others, just a personal pref), BUT if you used js when you ware debugging that jquery (1.0) plugin written in the free time of a 13 yo, who copy pasted a bunch from SO, well, it is not js' problem - deal with it. Same goes for PHP, i've been there where you had a single `index.php` with bazillion lines of code, did a bunch of eval and it was called MVC, but it also is evolving.. thing is all languages allow you to do some dumb stuff so YOU have to be responsible to not fuck it up (which you always DO btw, we all do). Difference is PHP/JS roll with it because the assumption is that you know what you are doing, which again - newsflash - you don't.
More or less I would blame that shit on businesses which decided to go with undergrads to save money instead of investing in their product, hell, I am in a major company that does not invest that doesn't care a whole lot about dev /tech stuff and now everybody's mother is an engineer - they care about money, because investors care about money (ROI) and because clean code does not pay the bills, but money does.
If we get all of the good practices and apply them to each language every one of them has it's place, that is why there is no "The Language", even if there was, we STILL ware going to fuck it up and probably it was going to be even worse than where we are now.
Study, improve, rinse and repeat... There are SENIORS and LEADS out there that are about 25-30 and have no fucking clue about the language, because they have stuck up their heads up the ass of frameworks and refuse to take a breath of clean air and consider something different than their dogmatic framework "way" of doing things.. That is the result you are seeing. Let me give you a fresh example to illustrate where I am at atm:
Le me works with ZendFramework 2.3-2.5 (why not, which is PHP5+ running on PHP7 [fancy, eh]), and little me writes a module for said project, and tries to contain it in its own space, i.e not touching anything outside of the folder of the module so it is SELF-CONTAINED (see, practices), during 2-3-4 iterations of code review, I've had to modify 4 different modules with `if (somthing === self::SOMETHING_TYPE)` as requested by my TL, which resulted in me not covering 3 use-cases after the changes and not adding a new event (the fw is event-driven, cuz.. reasons) so I have to use a bunch of ifs in the code, to check a config value and do shit. That is the way of I am asked to do things I hate what I've done and the fact that because of CR I have lost case-coverage, a week of work and the same TL will be on my ass on monday that things are now "perfect".
The biggest things is "we care about convention and code style"... right.... That is not because of the language, not because of me, not because of the framework - it is some dude's opinion that you hate, not the language.
New stuff are better, reinventing the wheel is also good, if it wasn't you would've had a few stone circular things on your car and things ware going to be like that - we need to try and try, that is the only way we actually learn shit.
Until things change in the trade, we will be on the same boat, complaining about the same shit over and over, you and me won't be alive probably but things will not change a bit.
We live in a place where state is considered good, god objects necessary (can you believe it, I've got kudos for using the term 'God Object'... yep, let that sink in). If you really hate something, please, oh god I beg you, show me how you will do it better and I will shake your hand and buy you a beer, but until then, please keep your ass-hurt fanboy opinion to your self, no one gives a shit about what you think, we will die and the world will not notice...6 -
in C I use {} for ifs even when they have a single line. for some reason, my C proffesor hated this. For him, this is the equivalent of Tabs vs Spaces.15
-
So my dear programming teacher really hates break statements... I mean really really really. He thinks it's better for readability if you don't break from any kinds of loops (not even ifs) well then we came across a switch statement in class. He says "breaks only exist because it's needed in switches" well how about returning from a fcking swith? or goto? then you need no break...
Is there anyone who could explain why I should NEVER use breaks and why it's bad in any piece of code? Why is it better to just use whiles because fors are apparently evil again? Srsly I just wanna ask him to show me some big code bases without breaks...8 -
first real program was an 8x8 maze game on my ti-83+ calculator. wrote all as nested ifs, and if you took one wrong turn it'd run out of memory3
-
I never thought clean architecture concepts and low complicity, maintainable, readable, robust style of software was going to be such a difficult concept to get across seasoned engineers on my team... You’d think they would understand how their current style isn’t portable, nor reusable, and a pain in the ass to maintain. Compared to what I was proposing.
I even walked them thru one of projects I rewrote.. and the biggest complaint was too many files to maintain.. coming from the guy who literally puts everything in main.c and almost the entire application in the main function....
Arguing with me telling me “main is the application... it’s where all the application code goes... if you don’t put your entire application in main.. then you are doing it wrong.. wtf else would main be for then..”....
Dude ... main is just the default entry point from the linker/startup assembly file... fucken name it bananas it will still work.. it’s just a god damn entry point.
Trying to reiterate to him to stop arrow head programming / enormous nested ifs is unacceptable...
Also trying to explain to him, his code is a good “get it working” first draft system.... but for production it should be refactored for maintainability.
Uggghhhh these “veteran” engineers think because nobody has challenged their ways their style is they proper style.... and don’t understand how their code doesn’t meet certain audit-able standards .
You’d also think the resent software audit would have shed some light..... noooo to them the auditor “doesn’t know what he’s talking about” ... BULLSHIT!9 -
so... 9 years ago we had this super awesome codebase. 1 file, complete logic COPIED to be used in ui and service/daemon. I scrolled to the middle of the file and there was no source. it was out of bounds of my monitor to the right because of nested ifs. ok... what the fuck!! the worst part: I had to implement a new FEATURE into this mess. 2 days. I said it would not work as expected because the feature was not thought through. but project said let's gooooo! ok there I was, a junior with an impossible to implement feature and a codebase from hell. I've implemented something, all night long. next day it was the problem of the consultants. they called me, I told them why it's impossible that this would ever work, they understood and talked to the customer. he accepted the solution. WTF?! anyway, in those days I thought about quitting developing software as my daily job....4
-
It's always fun to see some less experienced folks struggle with the shell :D
- quotes (single/double)
- subshells (and lost updates)
- variable substitutions (#, ##, %, %%, /, //)
- IFS
- environments vs variables
- associative arrays' limitations
and many more ways to drive the person crazy :)
I remember the times when I used to spend days-weeks over some problem - only because I didn't know how shell works. But it was worth it :)
Now I can watch others be tortured in the shell because they refuse to listen to my advice :popcorn:6 -
int someFunc()
{
int result = -1;
// imagine all the fucking ifs in the world...
{
{
{
{
{
{
{
{
{
}
}
}
}
}
}
}
}
}
return result;
}4 -
So I wrote a python code and was waiting for +1 on code review and I needed to merge it fast. That shit of a reviewer took his time to finally NOT give a +1 with comment, "if statement has no else part". OF COURSE IT DOESN'T HAVE ELSE PART. I DON'T NEED A ELSE PART. But to give him the benefit of doubt, I'd like to ask devRant community if they believe all ifs should have elses.14
-
-- What if JavaScript never existed?
-- What if HTML was a programming language?
-- What if our data online isn't abstract but physical?
-- What if geeks have their own country?
-- What if humans exist and we are the aliens?
-- What if the internet is state-owned?
-- What if we could download food just like every other downloadables?
-- What if my VSCode won't kill me when switched to light theme?
-- What if there was no gender and the word "female" is just an alias for "male"?
-- What if bugs could find and fix themselves?
-- What if there's no need for an account password?
-- What if Linux was owned by Microsoft?
-- **What if I could tell my boss that I'm tired of his fucking job without actually telling my boss? This is the actual what if.**27 -
Why the fuck these managers can’t understand that you can’t build a full blown system with in a week. After building a demo driven application to show the client you can tell the client we are fucking ready to launch the damn thing . I FUCKING MENTIONED BEFORE GOING TO THE MEETING ITS NOT RELEASE READY GOD DAMN IT.
Now when I say we can’t launch this app we need to fix things . THE FUCKING MANAGER HAS THE GUTS TO SAY “one day is enough to fix the issues right ? Shouldn’t be a big deal for you to fix this” .
Kill me now 🤬🤬🤬🤬🤬7 -
$a = 1;
$b = 2;
echo ($a < $b) ? ($a > $b) ? 'This is totally fine' : ($a < $b) ? 'This is not ok!' : 'Perfect' : 'No problem here';
Why do people do this?!
(And I mean nested ternary ifs, not coding in PHP :P)16 -
μRant
Normal languages for longer ifs:
if ( (condition1)
|| (condition2)
|| (condition3))
Go:
if (condition1) ||
(condition2) ||
(condition3)
That OR at the *end* of line deeply disturbs me10 -
This is so annoying, I had 9 diff. jobs the past 2 years and this is my 10th and if this doesn't change I might reconsider my options again.
I came to work at a company that pays me like a Junior and treats me as an intern. My 20yo "boss" who acts as a project owner/lead dev doesn't want to learn anything new and sees any improvement as a waste of money. The problem is he thinks hes a great programmer but he doesn't know shit. Im mainly working on the Laravel installation because "I claimed I know Laravel". And its absolute garbage. They haven't used a single Laravel features besides routes and everything else is vanilla PHP. They write for loops that loop through $_REQUEST to remove a single character. Write 100 deep nested ifs and they abuse Elasticsearch to the point ES crashes because the program is using 1000 deep multidimensional arrays. Its only a webshop...
Everytime I try to make a suggestion like making the master branch protected, doing code reviews etc etc I get shut down because they are autistic and don't want anything to change.9 -
Ah, when you run into a bug that only has 7 google results, and have of them is in Russian for some reason. Gonna be a long day.5
-
Just started teaching my brother some programming. He is the type of guy that is always outside and almost never uses a computer.
So after teaching him a lot on dictionaries, ifs, etc. I ask him to make a dictionary app.
This is how he proceeds to name his variables:
var theOne = new Dictionary
var f***face = Console.ReadLine()
if (theOne.Contains(f***face)) {
var faffaf = Dictionary[f***face]
Console.Write(faffaf)
}
(Note this is simplified C#)
This is after I told him a few times that you should name your variables so others can understand what they are.5 -
Anyone else just nest a bunch of ifs and loops and feel absolutely disgusted but it works so you don't want to refactor it?5
-
Little bit of background I've been a front end developer for the past eight years not a good one but I get by. Last 4 working with consulting firms for fortune 500 clients. Big projects big plans big structure, following someone else's lead and just knowing the basics of code reviewing, git flow, code deployment and everything else... life happens and i end up as a front end developer for a big company not tech related that wants to depend less from consultants and do more in house dev. Seems a pretty straightforward project front in angular. Back on python doing queries to a database with sql server. I finish the on-boarding and after two weeks finally get access to the repos. Worst spaghetti code I've ever seen. Seems like someone took a vanilla script project from 10 years ago and push it into an angular tutorial project. Commented code, no comments for the code, deprecated functions still there, no use of typescript nested ifs hell. I try to do my job doing new features do comments clean up a bit. Senior developers get annoyed6
-
Dear X. There's an obvious error with the way you're merging arrays; instead of conditionally adding items to the existing array, each condition overrides any items added by the previous conditions, which is clearly not the desired behaviour. I'd love to add a test to illustrate this behaviour, but you're not using them. I'd also love to create a simple pull request, but for some fucking reason you're using the worst possible version control system so I can't do that. I've submitted a support ticket along with all the code needed to fix this silly mistake, but apparently you either don't understand 2 lines of your own fucking code, or you didn't even bother looking at it before posting a shitty generic reply about "needing more information". There is no such thing as more information. There are two IFs, and they are supposed to add items to the array, not override any previous items. It's written in your own comments, and it's pretty obvious from the way the rest of the function merges those items.
Also, use a fucking linter, your code is a mess.7 -
Ive been working on pseudo-Java (ie some 3rd company's UNDOCUMENTED programming language) that they parse into Java in their backend
It doesnt even support if-else (only ifs and elses) or a boolean combination of False and OR together lmao
mainly a GRPC middleware-language
Given its lack of features (arrays/collections) or documentation, I just had to implement a flag-array using a 0-1 string
Im throwing exceptions unless combined strings equal Lengths and is only 1s
living like in 80s-90s 💀7 -
the person who wrote the code I'm maintaining had just learned try {}catch {} seriously, the guy preferred using try catch over ifs...11
-
When I’m getting to 100k MRR, if I have any developers but me, I’m gonna spoil them. I mean making them obscenely spoiled. Here, take your 4 times the market salary. Enjoy the culture and never leave.
Why? Because my architecture approach makes products that don’t need many devs, plus I don’t like making useless features. Every product has a scope. Every scope can be completed. “There are always tasks” notion is wrong.
Also, because to me 1000% and 10000% margins aren’t different at all. Those who seek MOAR and MOAR money, amassing more money than they can ever spend, do it out of fear.
I don’t have any kind of fear. Those who looked their death straight in the eyes don’t fear materialistic misfortunes.
My favorite word is “enough”. I speak it to myself several times a day, over and over, like a mantra. It helps me overcome but-what-ifs that plague people to the point of using next.js just to make trivial saas apps that can be replaced by Excel in one week of work.8 -
const ifs = i => {
if (i === 1) return '2'
// (a lot more ifs)
}
const switches = i => {
switch (i) {
case 1: return '2'
// (a lot more cases)
}
}
console.time('time')
for (let i = 0; i < 1_000_000_000; i++) ifs(i)
console.timeEnd('time')
// time: 637ms
console.time('time')
for (let i = 0; i < 1_000_000_000; i++) switches(i)
console.timeEnd('time')
// time: 949.524ms25 -
If you're reviewing someone's code, do you run/test the code before reviewing the logic? Or do you review logic before running the code?4
-
Do you need a degree to become a software engineer ?
Now this is a question I’ve seen many people ask. I personally have no degree and I’ve been doing programming for the past 10 years (since I was 18 ). Whatever I learned, I learned from reading and watching tutorials.
So far It wasn’t a problem for me.
What do u guys think and what is your experience is this matter ?9 -
I wanna make a c+friends language and it'd be dev friendly and will throw lots of errors on compile to show love. Also it'll compile slower with each newline so you can always say "it's compiling" there will be classes but people instead and then instead of new I'll have create. As for loops let's go with a friendly do while loop and dontdo while as normal while or dowith i while to have a friendly for loop. Instead of ifs let's say decide() and instead of else let's have or. Instead of functions I'll have well you need no functions you'll have jumps and tests before jumps just like assembly has. Oh and everything will be a pointer because then it runs nicer. To create a variable you can't use = because that's the equal sign in decide you need to use "var int myint is 69" because why not. Then to print to the console "console.outputstream.out(myint)" instead of threads I'll have please like "please work" where work is a jump target. I hope you'll enjoy this language ^^
-
Started a new contract:
Dev: "here, take this draft document containing a rough explanation of the requirements and write this service that exchange messages with these two subsystems"
Me 😐"ok"
-- couple weeks later --
Dev: "oh btw, you should go through ALL the fields in those messages described in the 'documentation' and double check them because we use millimeters and they use meters, we measure milliseconds and they use seconds. You should handle conversions when you deal with those messages"
Me (in my mind): "fucking son of a bitch! Why didn't you tell me this little piece of information at the beginning so I could have accounted for that instead of bloating the code now with your spaghetti style, full of horrible hacks, ifs and workarounds?
Me 😐: "sure, I will"
(don't worry, in the end I managed to find a clean solution for that 😉) -
Tired of all those timetables, application, motivational quotes ...
Coded my own assistant : Robo1100
Still full of ifs but properly understands what I mean (I don't have s very wild vocabulary )
Can I call it artificial intelligence?
Some of his features:
- determining current tasks according to date and time
- tracks the task and show you how many percent you've done
- plays different musics according to your mood (if you start nagging he'll play motivational rock and so on)
- does simple calculations for you
-gives you simple informations like time , whether,...
- remind you the events of the day
- reads a rsnfom cool quote at startup
- most importantly speaks with s human voice
-...
Any recommendations?7 -
StackOverflow locked my account. I'm hoping someone here might be kind enough to help me with a bash script I'm "bashing" my head with. Actually, it's zsh on MacOS if it makes any difference.
I have an input file. Four lines. No blank lines. Each of the four lines has two strings of text delimited by a tab. Each string on either side of the tab is either one word with no spaces or a bunch of words with spaces. Like this (using <tab> as a placeholder here on Devrant for where the tab actually is)
ABC<tab>DEF
GHI<tab>jkl mno pq
RST<tab>UV
wx<tab>Yz
I need to open and read the file, separate them into key-value pairs, and put them into an array for processing. I have this script to do that:
# Get input arguments
search_string_file="$1"
file_path="$2"
# Read search strings and corresponding names from the file and store in arrays
search_strings=()
search_names=()
# Read search strings and corresponding names from the file and store in arrays
while IFS= read -r line || [[ -n "$line" ]]; do
echo "Line: $line"
search_string=$(echo "$line" | awk -F'\t' '{print $1}')
name=$(echo "$line" | awk -F'\t' '{print $2}')
search_strings+=("$search_string")
search_names+=("$name")
done < "$search_string_file"
# Debug: Print the entire array of search strings
echo "Search strings array:"
for (( i=0; i<${#search_strings[@]}; i++ )); do
echo "[$i] ${search_strings[$i]} -- ${search_names[$i]}"
done
However, in the output, I get the following:
Line: ABC<tab>DEF
Line: GHI<tab>jkl mno pq
Line: RST<tab>UV
Line: wx<tab>Yz
Search strings array:
[0] --
[1] ABC -- DEF
[2] GHI -- jkl mno pq
[3] RST -- UV
That's it. I seem to be off by one because that last line...
Line: wx<tab>Yz
never gets added to the array. What I need it to be is:
[0] ABC -- DEF
[1] GHI -- jkl mno pq
[2] RST -- UV
[3] wx -- Yz
What am I doing wrong here?
Thanks.17 -
Would you guys get annoyed if someone(me) made a habit of going through your code and cleaned things up, such as clearer naming, untangling ifs with early returns and so on.
I mean doing stuff that doesn't change the behavior, but makes it easier for the next person.9 -
My ifs teacher doing an HTML question from an example.
"Let me explain(thinks for a minute).never mind my coding is getting rusty"1 -
So I had this conversation yesterday while fixing yet another Windows laptop for someone else.
Other Guy = OG
Me = Me (Duh)
OG: So what are your plans after your apprenticeship?
Me: Uh, I'll probably start somewhere that's e-commerce related, kinda like my current company but somewhere else.
OG: Uh have you thought about being your own boss?
Me: Well yeah, but I wouldn't know how to attract customers and shit
-- This is the moment shit gets real
OG: OH BTW I heard that Germany is lacking AI developers, you should do that! It earns you shitloads of cash!
Me: Uhm.. well, that might be true b-
OG: There's no but dude, it's free money, you're smart.. I mean you can fix any computer, right? AI will be just as easy
Me: It's not like-
OG: Duh, don't make yourself look so bad I know you can do it!
Me: B..But I'm not interested in it at all
*silence for 5 seconds*
OG: Well.. I guess you do you then
After that we continued to have random chit-chat about his job and experience (He's a mechanic)
God I hate when people throw buzzwords around and try to convince other people to do what *they* want.
No, I don't want to develop a structure of 1000 ifs/elses, I'd rather keep doing what I'm doing, thanks!6 -
Well, I love react-native and how easy to build mobile app with it. but damn look at these folder sizes jeez1
-
personal projects, of course, but let's count the only one that could actually be considered finished and released.
which was a local social network site. i was making and running it for about three years as a replacement for a site that its original admin took down without warning because he got fed up with the community. i loved the community and missed it, so that was my motivation to learn web stack (html, css, php, mysql, js).
first version was done and up in a week, single flat php file, no oop, just ifs. was about 5k lines long and was missing 90% of features, but i got it out and by word of mouth/mail is started gathering the community back.
right as i put it up, i learned about include directive, so i started re-coding it from scratch, and "this time properly", separated into one file per page.
that took about a month, got to about 10k lines of code, with about 30% of planned functionality.
i put it up, and then i learned that php can do objects, so i started another rewrite from scratch. two or three months later, about 15k lines of code, and 60% of the intended functionality.
i put it up, and learned about ajax (which was a pretty new thing since this was 2006), so i started another rewrite, this time not completely from scratch i think.
three months later, final length about 30k lines of code, and 120% of originally intended functionality (since i got some new features ideas along the way).
put it up, was very happy with it, and since i gathered quite a lot of user-generated data already through all of that time, i started seeing patterns, and started to think about some crazy stuff like auto-tagging posts based on their content (tags like positive, negative, angry, sad, family issues, health issues, etc), rewarding users based on auto-detection whether their comments stirred more (and good) discussion, or stifled it, tracking user's mental health and life situation (scale of great to horrible, something like that) based on the analysis of the texts of their posts...
... never got around to that though, missed two months hosting payments and in that time the admin of the original site put it back up, so i just told people to move back there.
awesome experience, though. worth every second.
to this day probably the project i'm most proud of (which is sad, i suppose) - the final version had its own builtin forum section with proper topics, reply threads, wysiwyg post editor, personal diaries where people could set per-post visibility (everyone, only logged in users, only my friends), mental health questionnaires that tracked user's results in time and showed them in a cool flash charts, questionnaire editor where users could make their own tests/quizzes, article section, like/dislike voting on everything, page-global ajax chat of all users that would stay open in bottom right corner, hangouts-style, private messages, even a "pointer" system where sending special commands to the chat aimed at a specific user would cause page elements to highlight on their client, meaning if someone asked "how do i do this thing on the page?", i could send that command and the button to the subpage would get highlighted, after they clicked it and the subpage loaded, the next step in the process would get highlighted, with a custom explanation text, etc...
dammit, now i got seriously nostalgic. it was an awesome piece of work, if i may say so. and i wasn't the only one thinking that, since showing the page off landed me my first two or three programming jobs, right out of highschool. 10 minutes of smalltalk, then they asked about my knowledge, i whipped up that site and gave a short walkthrough talking a bit about how the most interesting pieces were implemented, done, hired XD
those were good times, when I still felt like the programmer whiz kid =D
as i said, worth every second, every drop of sweat, every torn hair, several times over, even though "actual net financial profit" was around minus two hundred euro paid for those two or three years of hosting. -
How to meditate, Kiki way:
1. Lay completely motionless
2. For every thought your brain generates, ask “Where did it come from?”
It’s difficult first time, but then you get used to it.
For me, anxiety manifests as itchiness and pressure in the heart area. But when I think in this specific way, anxiety shuts up, and my heart feels… actively good? Not a heart orgasm or something, just the feeling you get when you take off your bra after a long day, but condensed in one area.
Thinking this way is like reading a history book. History doesn’t tolerate what-ifs, and thus, the opinion of your anxious part — a so-called internal critic — becomes irrelevant. At least, I think it’s how it works, I’m not a therapist or something.
Everything I analyze traces back to my mother. I mean EVERYTHING. What a manipulative bitch indeed. You probably missed that, here it is: https://devrant.com/rants/9940652/...
Meditation became a bad word recently. It’s something you hear from self-help gurus and other scum alike. Despite that, here is the simple way to meditate that works. Use it!67 -
Having a hard time thinking the alternates to if statements is a good idea. I was genuinely curious how this was done. The examples I am finding seem to just spread the logic everywhere across multiple objects. To me this makes the logic objectively less clear. I didn't understand the obsession with objects until I saw the examples that creates a fuckton of boiler plate objects. How someone can say this is preferred over a few if statements boggles my mind. I actually am trying to understand the functional mindset as well. It is not going well for me. I can sorta see some value in using a map. Technically a lookup could be faster. But again it spreads the code all around adding more boilerplate.
https://blog.bitsrc.io/reduce-if-el...
https://dev.to/phouchens/...
Is it because these are contrived examples? I initially searched to find ways of reducing ifs in a functional approach. I did find it in the second example. I was however hoping to find that by lazy eval or something. I see people making references to how one you "get it" functional logic is easier to understand and evaluate. I cannot tell if this is straight up gaslighting or my brain is just too fucking imperative.11 -
Php suxx asss. I`m at my second php dev job and I recommend all newcomers to stay away. Both projects were full of shiat developed by people with no technical background before. The current project I work on is just a bunch of nested if else like 10-15 blocks and after you finish booom there s another block of ifs . The fucking code looks like a wave. There were also some files named like file1.. file15 . Fml4
-
Inherited a massive code base today... All JS is still being accessed via global scope... what are modules & modular design even... SOLID and DRY are things that clearly never crossed the devs mind during inception of this beast... and to top it all off all there is a weird BEM / SCSS style going on that somehow manages to confuse the IDE... thus all style helper utilities in the IDE are useless...2
-
!long rant
Trying to work from home is always a pain, since we need to use company laptops (no ifs, ands or buts about it).
Yesterday I took the laptop in to check for updates that just wouldn't run while at home (my first mistake), and I couldn't get past the "Press Ctrl+Alt+Delete to login" screen, laptop keyboard didn't seem to be registering clicks, and an external keyboard wasn't either (and I forgot about the on-screen keyboard). A couple of restarts later with no further changes to the situation, the laptop then didn't get past the BIOS screen.
So I called support (my second mistake) and logged an incident.
Couple of hours later someone comes to my desk and asks about the issue, so I describe it, show them (by now the laptop was once again getting past BIOS screen), and leave them to it. Since these laptops are just used as preconfigured VPN and RDP gateways, I said it would be okay if he just wanted to reinstall the OS (my third mistake).
Several hours later, after staying late last night waiting for it to finish, I loaded my profile, installed updates, shut down, grabbed my stuff and left, without checking VPN or RDP over WiFi (my fourth mistake).
Turns out that some of the buttons on the keyboard just no longer work, but now USB keyboards do work, and I can just use OSK to login while out. I figured this would be my only issue with things, and that it was acceptable.
This morning I attempt to use the laptop, and forgot about OSK and the faulty delete button, so spent a few minutes on that. Try to connect to WiFi and find it can't connect, because of course, it doesn't remember the WiFi password, so I root around for the code in some drawer, enter it, and it works. VPN tries to connect and... get told to insert my smart card, which is already inserted, because the driver is wrong!
So I'm sitting here writing a post, not quite believing that I'm considering cancelling my plans for the day to go into the office because of a bloody driver issue now...1 -
Now where do i start. Hmm. Oh. How about a mountain of nested ifs. Or, super god codes. How about some unreadable variable names.
-
I think I had another insight.
Long story short, you're not the main character. You're not an NPC either. You're a spotlight!
Looking at yourself in the present doesn't make sense. You're not gonna understand yourself this way. In general, you're nothing but a history. In the present, you're an unbiased observer reading a history book.
This way of thinking is hard to pick up, but in a nutshell, for every emotion you feel, ask yourself: "Where did this feeling come from?"
This framework immediately takes the guilt away. It is what it is, the history doesn't entertain what-ifs. Once you memorize your own history word by word, only then you can really understand yourself and be free of trauma.15 -
When my mom asked what would I like to have - sweet corn or Avacado.
I said - Let's document all the possible approaches and setup some time to discuss pros and cons.2 -
Question for iOS Swift guys:
Since Implicitly Unwrapped Optionals are now dropped for a while, and everything is an optional, hiw can I now declare property that has no value and intializer will not make fuss?
I used to do this:
class Bullet {
var calibre: Double!
}
This way I can avoid initializer which gets useful when there are properties which hold complex types, which get useful when writing tests.
If I remove ! Then compiler complains.
If I put ? Then My code becomes crap of guards and ifs to check for optionals.
Really hate this Optional thing in Swift. Half my time when I jave an issue is related to optionals.
Btw,
let x: Int! = 10
let y = x, yields y: Int? -
so I'm the new guy now, my new team write complicated, deep-for-no-reason IFs instead of a switch, gave me a shitload of resources to get up to date with their standards, insisted to every time make sure my code has been tested, then the first deployment I see THEM do breaks production, because a major fucking app had no tests whatsoever, also half of the team has 30+ years of experience in backend, laughs about TS on the server (which is actually fair) and I'm the frontend guy
challenge accepted4 -
I feel inferior.... :(
Maybe I used too many ifs...
and it took me 1hr it seems...
maybe i should go back to sleep...
actually i woke up at 2am and realized i was supposed to be taking a nap... so i sorta overslept by 6hrs... tho i still need to work tomorrow... ehhh... today.2 -
*Triggers OAuth request through browser
Returns : success and valid tokens.
*Another project triggers the same process and code.
Returns : well shit nigga, I know I use the same logic as above but fuck you. -
Entropy wins. More useless accumulated historical nonsense in each programming language. Complex software stacks impossible to reach the bottom. However C and C++ still there possibly even some Cobol and Fortran zombies. And we devs still writing our ifs and loops for that kind of legacy stuff.
-
God fuckin dammit, I swear to heaven if this bitch ass code returns IO.Exception file is being used blah blah blah even though I'm using filestream and streamwriter. I will lose my shit in this fucking office1
-
I'm trying to set value of a kendo js property using value from dB. I would like to do something similar to
template : "#= dataItem.Item1 #"
But I can't use template for what I'm trying to set -
How many if statements does it take to get to the center of this fucking code block?lol but on a real note, how many if or else ifs is considered too much?3
-
No ansible, go home. You can not compete with mature programs used worldwide for many years.
Your "main" function for get_url module has 200 lines with comments dividing "sections" with different ifs. And it's one of best of your modules...
Just look: http://bit.ly/2d4LhTr1 -
How should you override Equals in Java?
We have model classes with lots of fields and the we override the details equals to compare all the fields. I guess like doing a deep comparison.
And in all these classes SONAR is complaining about lots of ifs, complexity, etc.
And it's killing the analysis time... Old issue never fixed because whoever setup sonar was too incompetent to bother asking, researching, or fixing...
Is there a better way to override the equals to get the same result but without triggering SONAR issues?
Pretty sure this is a solved problem. And well if the top of my head, is just create a Util method that uses reflection like
Boolean equals( Object a, b, Class class)
foreach (String f: class, getFields()) {if !compare(class.getField(f,a),class.getField(f,b)) return false; }
return true5 -
Reworking old java apps. Holy shit im gratefull i can use spring boot.
But this code is handsdown awfull. Every file contains more ifs than other words. upto 6 layers deep. Thank god its at least properly commented.
But seriously how did this shit ever pass any QA. All legacy apps around here are a massive pile of if statements.1 -
Whenever I rant about JavaScript and it's terrible way of doing things differently and totally illogical in the way real programmers would do things versus webdev-scriptkiddies...
Whenever I laugh about these engineers who can only 'code' in Matlab...
Whenever I hear people consider configuring (of stuff like WordPress or RGB-Keyboard-Lights etc.) as 'programming'...
I wonder, if I'm just like the 'Real Programmers' back in 1983 who truly considered Fortran or Assembly to be much more superior than Pascal and someone who coded in the latter or even used a simple OS like UNIX couldn't get accepted as a programmer.
Found that old article about "Real Programmers".
It's worth a read.
http://pbm.com/~lindahl/...
Just consider someone writing modern computer programs without libraries, ifs, for loops and only gotos by hand from top to bottom...
Some day I want to start some modern project everyone else would do in some random modern scripting language and hack it down in assembly just for fun and to tell people, I did it. So I could call myself a Real Programmer too.2