-4

I'm working as a software developer for around 8 years now and have worked with mostly companies offering outsourcing services.The challenge so far was mostly - learn the new tech, showcase through a prototype/POC and implement it in the assigned project. Over the years, technologies changed, but nature of work remained the same - javascript, jquery, webforms, silverlight, MVC, etc. But now, am trying to transition to a software consultant role and one of the feedbacks that I recieved was - "Try to think in depth, as to not just use a feature but to relate it to the most basic concept that you know." e.g. as a best practice for string concatenation in C#, we know that we should be using stringbuillder and also know why we should be using it (string immutability), but the question was - How would you implement a StringBuilder class from scratch?

I'm not sure how to train myself for becoming ready for design thinking and making myself ready for in-depth thinking and analysis (since most of day to day tasks never require such rigorous drill-down).

PS: Sorry for long question and also even though the question is not suitable for platform, I would still be happy if anybody could point to a correct forum/community where i can reach out for guidance.

  • that's a weird question to ask. Are they testing your low level.net knowledge or is it a meta question? ie "copy the existing string builder", "implement memory space tests" – Ewan May 26 at 11:34
  • Actually, they were looking for people in senior roles to build reliable and scalable solutions. They wanted to check if I can only leverage existing solutions to a problem or build custom solutions too. – Vaibhav Singla May 26 at 11:40
  • not sure i would call "using stringbuilder" "leveraging an existing system" – Ewan May 26 at 11:47
  • if its just an interview question then I guess its off topic and general advice applies. "Of course normally you can just use an existing component, but here is an example of where I had to do a deep dive and implement a custom solution..." – Ewan May 26 at 11:49
  • 1
    how to ... - Use every "day to day" assignment to research/review/study the language's documentation of the classes, methods, etc. used. That existing code is good practical context for considering all those technical implementation issues. – radarbob May 26 at 15:37
1

How would you implement a StringBuilder class from scratch?

By thinking very seriously about why I have to implement StringBuilder from scratch.

The proper reaction to that question is to ask "why?". Without a good reason why all you're doing is showing off that you know how to implement your own StringBuilder if stranded on a desert island. Not typically useful.

Now if the current StringBuilder has a bug that's causing you trouble or is missing a feature that would be useful then being able to reimplement it would be handy. Being able to extend it would be convenient.

"Try to think in depth, as to not just use a feature but to relate it to the most basic concept that you know." e.g. as a best practice for string concatenation in C#, we know that we should be using StringBuilder and also know why we should be using it (string immutability) -

String immutability isn't why. A single concatenation of immutable strings works just fine without StringBuilder. The problem is multiple concatenations can't be optimized if you don't consider all the strings first. Doing that lets you allocate enough memory for all of them at the start without allocating O(n2) more memory. Big O optimization isn't just about CPU cycles. Memory use is important as well. Simply making strings mutable doesn't make this problem go away. This is about when you figure out how much memory you need, before or after you've used a bunch of memory you really don't.

Understand that and you might be able to reimplement StringBuilder without embarrassing yourself. Also might help you realize when fanatically insisting on using StringBuilder every time isn't warranted. If you've never heard the Shlemiel The Painter story I suggest you give it a read.

Try to think in depth

I read this as: show me you can do more than regurgitate rules to follow by rote. Show me you've thought about why. Software development is chuck full of people following rules they don't really understand. Are you just another one of them?

I'm not sure how to train myself for becoming ready for design thinking and making myself ready for in-depth thinking and analysis (since most of day to day tasks never require such rigorous drill-down).

Keep asking why. Keep trying to explain why. You haven't mastered a topic until you can explain it to someone who keeps asking why.

| improve this answer | |
  • thanks a lot, this helps. I'll start paying more attention to why best practices are indeed best and look time-space complexity more closely. – Vaibhav Singla May 26 at 14:23
  • @VaibhavSingla keep in mind, if you know n will be small, no ones going to care. – candied_orange May 26 at 15:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.