Have you turned down work because of quality of source code - Page 1
Forum section: electronics / general

author: snarkysparky
author_rank: Frequent Contributor
timestamp: April 27, 2020, 05:44:43 pm
content: I'm in a position where I may get the opportunity to go full time to work on a software project but the code base I will have to work withgives me nightmares. Haven't had to change it yet because we don't have a compile system but I have had to spend significant time tryingto reverse engineer what the code is doing. That said some comments about this code.It's a flat structure with many thousands of random functions just seeming to magically work together somehow. No hierarchy of control.Full to the brim with magic numbers in the source code.Using VxWorks RTOS but nothing in interface is documented.Virtually no comments. Authors were Japanese and English comments were attempted but still not usable.Variable and function names like Phtack2zu .... etc are the rule. Very few names provide any context.Vast amounts of abandoned code but not defined out or commented out , just not called.source is CSize is about 350 files.I am tempted to reject the job cause I just don't think I can ever make sense of this mess.Have you plowed through something like this or have you ever declined to work on it.

author: snarkysparky
author_rank: Frequent Contributor
timestamp: April 27, 2020, 06:25:28 pm
content: for exampleCode:SLONGkysChgAscdt( bind, strp, strlen )ULONGbind;SBYTE*strp;SLONGstrlen;{UBYTEascd;SLONGi;kysPadSet( strp,strlen,' ' );strp = strp + (strlen-1);for( i=0 ; i<strlen ; i++ ){if( bind == 0 ){if( i==0 ){*strp = '0';i=1;}break;}ascd = bind % 10;ascd |= '0';*strp = ascd;--strp;bind = bind / 10;}return( i );}

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 27, 2020, 06:27:41 pm
content: No comments, but the identifiers for functions and variables don't even help either!

author: jfiresto
author_rank: Frequent Contributor
timestamp: April 27, 2020, 06:39:54 pm
content: Quote from: snarkysparky on April 27, 2020, 05:44:43 pmThat could still work if it is an indefinite position that expects you to clean up the code and make it sensible. A friend took a job like that and spent a few years knocking some terribly ugly Windows and VB6 code into good shape. He subsequent migrated it to .NET and now has a job for however long he wants it. He made himself indispensable, by both now knowing the problem domain and being one of the very few that can address it (as demonstrated by the code he started with.)

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 27, 2020, 07:03:11 pm
content: I don't know how interesting the job otherwise is, so the decision is of course entirely up to you.But having to deal with a large code base you don't feel comfortable with can be a real PITA, and if you know this is going to last for a long time (and not something just temporary), you'll have to really think hard about it.And yeah, it looks likely that the company opening this position is expecting whoever takes it to save their ass with this hard-to-maintain piece of code, so it might well be your main responsibility, which would make the job even more uncomfortable.Good luck deciding!

author: capt bullshot
author_rank: Super Contributor
timestamp: April 27, 2020, 07:29:52 pm
content: Quote from: snarkysparky on April 27, 2020, 06:25:28 pmThis routine formats a number into a string, beginning at the end of the string (least significant digit). Does look a bit strange, but not incomprehensible. Does something similar (but not exactly) to a sprintf(strp, "0%6d", bind) ...One can even guess the meanings of the variables:bind -> binary digitascd -> ascii digitstrp -> string pointer

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 27, 2020, 07:34:25 pm
content: Sounds fun to me.A consultancy I once worked for was employed once (not me personally) to 're-write' a codebase where the outgoing developer had written it with the variable names all being expletives or such phrases... Apparently some were quite involved... of course it made their purpose somewhat tricky to derive.Understanding large code bases of undocumented code is a skill... make sure you charge for it."No hierarchy of control." ---> in very stack constrained environments this was not unusual.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 27, 2020, 10:42:54 pm
content: Quote from: capt bullshot on April 27, 2020, 07:29:52 pmGood job deciphering this piece of code.Yeah, it might be understandable once you get to know the author's conventions. It's not necessarily that badly written. But one thing that would definitely put me off though, is that judging from the above function, it's not even ANSI C. I would not touch that with a stick. But that's just me, someone has got to do it. Again, good luck!

author: ataradov
author_rank: Super Contributor
timestamp: April 28, 2020, 12:02:22 am
content: This specific piece of code is not all that bad apart from non ANSI C part. But that depends on the target device. May be the only available compiler is that old. Although VxWorks suggests otherwise.Whether I would work on something like that depends on a single (technical) factor - am I allowed to make code better as I go? If they insist that it must remain this way, you just need to add new things, then hell no. If this is just a legacy code base and they are looking to modernize it, then many times yes. I personally enjoy this type of work.This implies long term full time employment. If this is a contract job, then I probably would not do that.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 28, 2020, 09:20:10 am
content: No takers to re-implement the code example?It takes an integer value (bind) and a string buffer (pointed to by strp) with length (strlen)First it fills the string with spacesThen it converts bind to an ASCII representation which is right justified in the bufferand returns the number of digitse.g. 123 becomes " 123" returns 3So can you do better?

author: Psi
author_rank: Super Contributor
timestamp: April 28, 2020, 10:18:27 am
content: i would definitively make it clear in the contract that the current code is undocumented and you will spend significant time just understanding how it all works and rewriting sections.Give them a price and time-frame that takes this into account.Consider that you may not be the first person they have offered this job too.It may have been turned down multiple times before for the same reasons you outlined,so they may be willing to pay top dollar to get someone to do it,It really depends how your brain works, some programmers enjoy figuring out and fixing crappy code as long as they are being paid good money. While other programmers hate it

author: Mechatrommer
author_rank: Super Contributor
timestamp: April 28, 2020, 11:11:32 am
content: Quote from: capt bullshot on April 27, 2020, 07:29:52 pmi agree, its not totally incomprehensible. but you'll need some experience or knowledge under your belt. not really need a fancy experience, just some format converting experience or basic number converter normally available explained in book or somewhere else... such as this line clicks something...Code:strp = strp + (strlen-1);this tells we move the position of string pointer to the end of the string.. and then...Code:ascd = bind % 10;ascd |= '0';*strp = ascd;--strp;bind = bind / 10;take remainder (sort of base 10) of bind into ascd, format it somehow with '0' and put it at the end of the string and then moves the pointer backward toward the beginning of the string and fill it with formatted ascd. divide bind with base 10 again and redo...trying to understand a piece of library/code base will need a lot of work (but not nearly the work of reinventing it from scratch), patience and slowly walk through it, regardless if its readable or not (currently i'm doing such task on Marlin FW ver 2 for 3D printer to put it in my 5-axis CNC project). one simple trick is copy paste that piece of code into our "workframe", inject it with expected input and see what its output in debug mode etc... another fancier method is map all the files in the library for their dependency and correlation (this function calls to which functions in which files?). but it needs a proper managerial tool SW. i diy one long time ago, but not really a completed one. anyway, you'll know if you have some blood to it or not sooner or later. the reason behind why you are doing it also can drive you to move forward and more... if you think its not worth it, then its a "quitter" ymmv.

author: Syntax Error
author_rank: Frequent Contributor
timestamp: April 28, 2020, 11:35:26 am
content: It's good your prospective client has let you see the source code before you commit. Many clients/employers recruit stars who are experts in stuff like node, django or jenkins, and then drop them into their legacy CMS cesspool. Six weeks later, they're looking to fill their vacancy, again.My opinion, the code is dense, suggesting the guys who wrote it were proficient coders when it was written. So don't expect any major fails. Or the need to rewrite it. But don't fall into the trap of over promising. It could take 6 months to unravel this coder's mindset. Not to mention managing the client's expectation of what you can achieve with the little they gave you.Talk - ask what do they REALLY want you to do - or walk.Good luck.+++edit+++ Looking at the style of the code, it seems somewhat 'low level'. Maybe the developer was from an assembly language background?

author: ace1903
author_rank: Regular Contributor
timestamp: April 28, 2020, 12:22:57 pm
content: I experienced myself the same situation several times.It depends if there is QA test team or some form of requirement specification for the project.The worst case was when my employer wanted me to add a new feature on the existing spaghetti code.I did that and several errors were reported. I was sure that my changes can not be blamed for the errors.Then again I asked for a specification of how the product should work and perform in different test cases. I was told to look at the code and learn myself.Found that several software developers worked on it and each of them did their tasks but not knowing specification they introduced several fatal bugs.Now if I am offered a project with no documentation I simply refuse it.You can learn what code does but not what it should do. It is easy to get the wrong conclusions just by reading the code.If there is QA team you can ask which tect case fails, which tests are performed and expected results.One man show for project and under time pressure is disaster for health both mental and physical.

author: snarkysparky
author_rank: Frequent Contributor
timestamp: April 28, 2020, 01:22:38 pm
content: Well, the decision was made for me. They can't hire at this time and I am out the door.Was going to decline the work anyway. I don't like solving puzzles just to be solving them so i would be unhappy untangling that spaghetti code. I prefer to write my ownThanks for the input. They don't have budget for anyone else. Crazy times....

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 28, 2020, 02:24:57 pm
content: Quote from: snarkysparky on April 28, 2020, 01:22:38 pmI have seen that already. Yep, pretty crazy...

author: SimonR
author_rank: Regular Contributor
timestamp: April 28, 2020, 02:27:02 pm
content: Quote from: snarkysparky on April 28, 2020, 01:22:38 pmProbably the right decision, I have done this on a similar sized project, it takes forever. You have to convert the bits you are working on as you go along otherwise you run the risk of breaking it. This can take many times as long to do so you need your employer to agree that this is going to happen otherwise you have no chance.The converted project is still running after 5 years and is much improved but I still find bits that have never changed.QuoteNot necessarily true. The example is original K&R C which had a limitation on symbol name length of 8 characters so everybody used cryptic names back then. Almost all C code looked like that.You could use longer names but only the first 8 characters were counted so you ran the risk of mixing variable names up and not realize.Code:May be the only available compiler is that old.Non ANSI C still compiles in C99, or at least the example here still does. The only major difference is the parameter definitions appearing before the { and that still works. Probably the next problem are the differences in what is determined to be undefined behaviour.Code:No takers to re-implement the code example?If you don't care what the exit value is then you could just replace it with something likeULONG strlen = 10;sprintf(strp, "%10ld", bind);However if you care about the number of digits in the decimal number then you have to re-write the existing function.Also you might have a dynamically sized buffer which is a problem for the format string "%10ld"

author: Siwastaja
author_rank: Super Contributor
timestamp: April 28, 2020, 02:29:18 pm
content: A totally flat huge blurb of C functions, some of which are unused, while not a dream job, is not at all the worst possible. It looks nasty, but there is alimitto its nastiness: it likely isn't totally unsalvageable. This kind of project looks like horror on the first sight, but you start making sense on it piece-by-piece: you can easily delete unused code, then follow function calls.Naming conventions are like assholes, everybody has one and no one likes the others'. You start getting used to the random-seeming names.The "benefit" of such design is that if any of those functions areactuallydoing something difficult to reproduce, they are easy to reuse as-is because there is no huge tree of architectural dependencies like in an over-engineered and badly designed object-oriented cathedral which is not too uncommon at all. Such a case maylook likevery well-structured on surface, but once you start working on it, you find out you can't do anything on it since it would need complete redesign. Such projects may have tens of thousands of source files which all contain almost exclusively boilerplate.If you have 350 C files with a bunch of functions each, you have good chances of being able to actually locate the interesting parts (algorithms and datatypes) and follow them.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 28, 2020, 06:24:19 pm
content: Quote from: SimonR on April 28, 2020, 02:27:02 pmNice try but think of the overhead of pulling in sprintf... might be too expensive... might pull in too much code and static stuff... if it even exists.

author: SimonR
author_rank: Regular Contributor
timestamp: April 28, 2020, 09:18:39 pm
content: Quote from: NivagSwerdna on April 28, 2020, 06:24:19 pmIt does exist, sprintf is in K&R version 1, look it up, I did that's why I suggested it. It uses almost no resources just 0x58 bytes of code and no ram according to my MAP file. I have only 32K of RAM in my system which is very heavily used by my application.Plus its only a suggestion, a time period compatible one. You would have to move to a newer compiler to get longer names anyway

author: ataradov
author_rank: Super Contributor
timestamp: April 28, 2020, 09:21:39 pm
content: Quote from: SimonR on April 28, 2020, 09:18:39 pmThere is absolutely no way printf() uses 0x58 bytes of code. Typical printf() on Cortex-M0+ is about 20K of code.So it is possible that compiler is smart and parsed the string and substituted some version of itoa().Obviously if you already use printf() some place else, it does not really matter, might as well use it here.

author: SimonR
author_rank: Regular Contributor
timestamp: April 28, 2020, 09:43:54 pm
content: You are of course correct I only did a quick look without thinking about it.Adding up all the bits of my xprintflarge library seems to add up to about 14K, there's probably some dependencies as well. I used to use the small library until I needed something it didn't support.I originally avoided it for a very long time for fear it used too much resource, then discovered it wasn't as bad as I thought. I don't care so much about the code size as much as the RAM footprint.In any case it was just a period correct alternative suggestion assuming you didn't depend on the returned count being correct.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 28, 2020, 10:52:28 pm
content: Yes, compilers are smart enough to do that.Likewise, if you're only using printf() with no format tags, the compiler will usually call puts() instead, which takes very little code.

author: andersm
author_rank: Super Contributor
timestamp: April 29, 2020, 06:07:02 am
content: Dealbreakers for me would be unrestricted use of globals and pointers. With cryptic, but otherwise correct code, you have the option of encapsulating it, and add documentation as you go along, but if it's also broken you're probably better off starting over from scratch.If they were explicitly looking for help with modernizing their code base, there are people who specialize in that, but as with all experts, they can be expensive. You just have to make the judgement call if it'll save money in the long run.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: April 29, 2020, 09:12:27 am
content: Quote from: NivagSwerdna on April 27, 2020, 07:34:25 pmI once worked on a codebase of a piece of software that my then-employer's parent company bought out from a third-party consultancy that ran it as a SaaS for their clients (of which my employer was one). The lead programmer apparently favoured 'shit' as his one-size-fits-all noun that was used liberally in comments all across the code. For example: "copy the shit", "take the shit from the DB result and put it in the list", "delete this shit", "format the shit", etc, etc.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 29, 2020, 09:23:05 am
content: Quote from: SimonR on April 28, 2020, 09:18:39 pmHarsh! Just because something existed in a language specification doesn't mean it existed in the development environment and even if it did its use might not be advisable depending on hardware constraints. Specifically you get very dependent on how clever the linker is and if it can be very specific and also using any library adds additional stack constraints.My memory fails me but I believe in some PICs you only got about 6 levels of stack... something tiny and you need to account for an interrupt too... in that kind of environment calling anything (unless the call is optimised out) uses precious resources.

author: AndyC_772
author_rank: Super Contributor
timestamp: April 29, 2020, 09:54:02 am
content: At least you had the chance to see the code before deciding to take the job or not. TBH the state of the code wouldn't worry me nearly as much as how easily - or not - you can test any changes you make.I've had to turn down a couple of software jobs for just this reason, and one in particular sticks in my memory."Give us the code and 3 weeks, and we'll tell you if it works or not" wasn't the answer I was looking for.

author: Mechatrommer
author_rank: Super Contributor
timestamp: April 29, 2020, 10:53:06 am
content: never took a programming job except for freetime hobby and once as a RA 20yrs ago but if someone come to ask "program this and if its work you get your money, otherwise your weeks of hardwork will go down the drain" i will say to them "you can go f yourself".

author: Syntax Error
author_rank: Frequent Contributor
timestamp: April 29, 2020, 01:31:13 pm
content: Quote from: HwAoRrDkClearly that hack did not go for peer reviews... or he was a 'lead programmer' so code shone out of his var_se anyway?Lord of the Rings and Hogworts references litter code from script kiddies. Even Manga and K-Pop gets a look in. Which is easier to reverse engineer than code where every object is called 'o'.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 29, 2020, 01:41:58 pm
content: Yeah, using comments like this either means that was a lone developer with no code review whatsoever (the most likely), or the whole team was a bunch of weirdos.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: April 30, 2020, 10:07:04 am
content: The ironic thing was that the code was pretty good. It's just the comments were of a scatological nature and lacking a bit in insight.I have no idea whether any of the code was peer reviewed. The 3rd-party consultancy that developed it had 50+ developers, but I don't think more than a handful of people ever worked on the thing.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 30, 2020, 02:05:06 pm
content: Putting shit like this everywhere as a placeholder looks a bit like the smurf language... only a bit more offensive.

author: IDEngineer
author_rank: Super Contributor
timestamp: May 06, 2020, 11:05:18 pm
content: Indirectly, yes.A former employer once sent me to evaluate a code base they were considering buying from a bankrupt technology firm. To my horror, the code had NO comments, no documentation, nothing. Just source. And it was basically unreadable with variable names that bore no relationship to what they were used for, etc. I recommended STRONGLY that they skip this "opportunity" since I viewed it as a money sink that would not only work out poorly, but also make anyone who touched it (read: Engineering) look terrible. Even the representative from the bankrupt firm that managed my access to it said he'd run, not walk, away from the purchase.Nevertheless, our Sales and Marketing droids forced their way and my employer bid on the asset. Thankfully they got into a bidding war with another company, and lost. Sales and Marketing were furious, but I told everyone in Engineering that our department and the company as a whole had dodged a bullet. You just know that Sales and Marketing would have been first in line to criticize Engineering's inability to make this code work.

author: Tomorokoshi
author_rank: Super Contributor
timestamp: May 17, 2020, 11:27:19 pm
content: In this case, a lot of what drives the decision comes down to:1. What is the timeframe of getting the system to be somewhat documented and understood?2. What are the requirements for any upcoming changes? What is the schedule for those changes?3. What is the willingness of management to take on the costs in software analysis tools to help figure it out? Let's ballpark $25,000 as a starting point for various tools until something is found that helps. This doesn't include research and engineering time.4. What is the projected lifetime / revenue of the product line after updates?5. Do you have access to all the tools used by the previous engineers, or are licenses, software, and dongles lost?6. If this is an embedded system, are there issues with circuit board updates or part obsolescence?The effort breakdown is probably something like 10% programming, 30% engineering, and 60% management until the updated system gets running smoothly. Note that it's possible that the updated system will never actually run smoothly, or that market conditions will eventually cancel the project.

author: hulk69
author_rank: Contributor
timestamp: May 19, 2020, 01:14:56 pm
content: Oh man this post is resonating with me so much!I am working on taking over/maintaining a huge C project done by people who had no business writing code.This is the most depressing time in my professional carrier. This thing is a living nightmare, your code compare to it looks like art!

author: westfw
author_rank: Super Contributor
timestamp: May 22, 2020, 02:53:42 am
content: There's a certain challenge and satisfaction that you can get from learning how particularly mysterious code works.Whether I'd turn down "work" for that sort of thing would probably depend on whether the employer understood that that was going to be the problem. If they know they're in deep crap and are willing to spend the time and money to get it fixed, that's an entirely different situation than if they think their current code is wonderful and they just need someone to make a few changes.

author: guenthert
author_rank: Frequent Contributor
timestamp: June 05, 2020, 04:38:22 pm
content: The quoted code might not have been pretty, but it was by no means obfuscated. I would say about standard for older C.Unless it's assembler, I don't expect much comments within the code, but appreciate if there is (as long as it (still) matches the code, which sadly isn't a given). More important to me is documentation outside the code -- some kind of product requirement document, worklog, changelog etc. . Is the code under some version control (if not, that might be the answer you're looking for), how do the check-in comments look like? Is the motivation of changes documented (or does the author only state the obvious, as in "added foo() to bar.c", which is all too common or mysterious, as in "fixed baz()")? Is there a defect database (for larger projects IMHO a must)? Is that defect database consistently(!) referred to in the version control check-in comments?And yes, I chose to decline a work-offer once, but that involved a collection of shell scripts a different company already declined to work on ...

author: Michael Rempel
author_rank: Contributor
timestamp: June 05, 2020, 08:26:34 pm
content: Personally I am a professional software architect. When I looked at those snippets I saw that it was written by a total amature. Experienced developers acquire a few really good ways to do things over the years. That code has none of them.I think you were facing one of two possibilities:1) they have hired the cheapest dev they could find in the past. It is now biting them hard.2) the guy who wrote it is the one trying to hire you.Both of these are a nightmare. Good choice to let it go.And by the way, yeah I have let projects go. Even when I was very hungry, for just these reasons.Be careful with people like them, they can bad mouth you and cause you lots of grief. Wish them well and forget to anwser their calls.

author: Warhawk
author_rank: Frequent Contributor
timestamp: June 05, 2020, 10:02:18 pm
content: Run Forest, RUN!

author: westfw
author_rank: Super Contributor
timestamp: June 06, 2020, 05:44:05 pm
content: With the proper experience, you pretty much INSTANTLY recognize that last panel as a mouse trap...

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 06, 2020, 06:02:46 pm
content: Perhaps, but it's too large to hold a mouse. It seems more like a... developer trap?Tim

author: AndyC_772
author_rank: Super Contributor
timestamp: June 06, 2020, 06:37:59 pm
content: Quote from: westfw on June 06, 2020, 05:44:05 pmExactly!More specifically, it's the mouse trap that you end up with if you just#include "mousetrap.h"and don't think too hard about how that particular mouse trap is implemented, what resources it requires, or how long it takes to execute. After all, it's a library that someone else wrote, a long time ago, so it must be tried, tested, reliable and fit for purpose - right?

author: stafil
author_rank: Regular Contributor
timestamp: June 07, 2020, 01:45:43 am
content: How easy can you find another job?

author: dietert1
author_rank: Super Contributor
timestamp: June 07, 2020, 09:33:01 am
content: Yes, try to get that job, with a contract including your findings. Which means design and docs, no coding. You seem to be the right person to recover that project from the dumpster. Later, if you write one file per day, after another year the project will be yours.I have been recovering many projects like this - for years. Somehow it stopped after one large year 2000 project that took me about five years. It gave me so much income that i could build my own business, yet i may have become a bit messy, too.Regards, Dieter

author: tkamiya
author_rank: Super Contributor
timestamp: July 07, 2020, 06:12:31 am
content: A lot of production code I've seen are like that.... When the code was originally written 10+ years ago and multiple people has had their hands in it, spagetification tends to happen. Workaround of workaround of workaround isn't fun to fix. But it's a reality in a lot of places.Every now and then, I get fed up with it and take out all that code and clean it up.