r/learnjava • u/[deleted] • Jan 17 '20
So I had an internship interview
I'm a second year CompSci student and as part of my degree we have to do a placement in 3rd year. I had an interview yesterday which went okay, and then I got a coding challenge at the end.
I was given 1 hour to print the fibonacci sequence for n integers input by the user. For example, user enters 5 I print 0, 1, 1, 2, 3.
So that was all good and I got it done in like 6 mins, and the interviewers came in to review it.
. They said I shouldn't have created an array because its inefficient as I was only asked to print out the code. . They also said the name fib for the array was kind of unclear and that I could have used the whole word. . Also pointed out things like putting a space between ) and {. . Said my method name printFibonacci was a bit misleading and could have been 2 methods since I also calculated it.
As much as I appreciate the advice to clean up the code, as a year 2 student intern you are still only at the stage of writing functioning code and not completely clean code. I feel quite disheartened after leaving and was just wondering if anyone else has experienced this in an interview and if so, what was the follow up like? Did you get the job?
Thanks for listening!
EDIT: I don't want it to come across as bashing the interviewer or anything like that, it did seem more like advice, was just trying to see if anyone had similar experiences with this.
EDIT: So I ended up getting a second interview last week, and today I was offered the job! Thanks all for the feedback and support!
Here is my code: https://pastebin.com/FWgX9m9U
12
u/Sylicas Jan 17 '20
Hey, those were great advices that they gave. All the more to foster good habits while you're still starting out, rather than having to unlearn and relearn it.
See it from the business perspective - after your internship, you're most likely not staying in that company for long. Thus, good coding practices are as important as your ability to code as well if they do not want to waste time and refactor shoddy code for longevity's sake.
3
Jan 17 '20
That's a fair point but you also have to look at it from an interns perspective, I have no work experience with writing clean code and only have 3 semesters of university experience to go of. Do you really think this is enough time to be writing industry standard code?
The reason I am applying for these internships is to learn how to write cleaner code and implement better coding practices. I was given an hour to do a task, I had it working in under 10 mins.
I wouldn't have said my code is shoddy, apart from an unnecessary array everything worked fine, I even implemented it to take user input for 'n' which I don't think was needed.
7
u/Sylicas Jan 17 '20
Hey, good on you for working out the logic quickly. So, then, did they give you time to improve on the code after their feedback? And more importantly, have they gotten back with any offers yet?
With regards to writing industry standard code, well, I would say it depends on the mentorship you have and the books you read. It's definitely possible to learn and write industry standard code within a few weeks, as long as you keep improving and are receptive to the feedback.
2
Jan 17 '20
No, even though I technically had another half an hour or so left of the hour, after the feedback, they did not let me write a more efficient solution.
I did offer, but they said I didn't need to.
I guess industry standard code is something I will have to look at on the side, at the minute in classes we have only sort of covered up to Object-Oriented programming, with Data Structures and Algorithms starting this coming semester.
Any recommendations of where to go to learn industry standard practices?
7
u/Sylicas Jan 17 '20
Haha, well, interviews aren't going to get any easier, so best to learn from it and carry on.
Fundamentally, industry-standard code should be easy for new people to read and easy to edit. It's simple, but there are many best practices for it.
Many resources exist out there, but a good starter resource is Clean Code by Robert C Martin. Even up to now as I have started work, I still read it time and again to evaluate.
2
4
u/indivisible Jan 17 '20
On the flip side of this, for you to learn those things, somebody is going to have to point them out or teach you a about them at some stage, right?
Take it as positive criticism and try to learn from it. You got honest useful feedback which honestly is more than you'll get from a lot of places. The reviewer didn't necessary have to spend the time pointing out places you could improve no matter how minor they seem to you in terms of compile/execute rather than "enterprise code" standards or practices.2
Jan 17 '20
I am 100% taking this as a great learning experience. I maybe didn't put my point across so well, I'm not complaining so much about what happened, I was just more curious as to if this is commonplace in interviews, because I've ever had a proper structured code review before.
3
u/indivisible Jan 17 '20
So if it's less complaining and more query then yes, most code reviews may poke at or "nitpick" on things that you may not consider an issue or particularly important.
Sometimes that's because you may not have the experience or the "big picture" (yet) and sometimes it's just a minor asshole looking for anything to complain about but in either case don't ever let it offend you since it's always about the code, not you personally and usually there's something you can take from it and improve on or learn from.From your other reply to me:
I'm left to think: What else am I going to be expected to know that I haven't yet learned about?
There's always more to know no matter your level or experience. Good developers never stop learning. Also, nobody starts out knowing it all, we all made the same beginner mistakes and have had to spend time improving to get past the beginner stage. Just keep moving forward, take whatever advice you can get and don't stop learning.
And finally, just to be clear, nobody expects a recent graduate to know all these things either; it's expected that you'll need time and training to reach the same level that somebody with years of experience is at. As long as you can take the feedback and learn from it you'll be fine.
5
u/endisnearhere Jan 17 '20
If the reason you’re applying is to write cleaner code, why are you trippin when they show you how to write cleaner code? This interview sounds like it was a good learning experience.
2
Jan 17 '20
I'm not tripping about the criticism, I'm just posting here to see if that sort of thing is common or if I should be worried about it. Sorry if I didn't come across that way.
2
u/marvfone Jan 17 '20
He said that it was a requirement for his program. He sounds like he took it well and looked here to optimize the situation.
But, I can spin anything.
-1
u/chasingviolet Jan 17 '20
I mean, writing clean maintainable code that meets industry standards is a standard part of my school's intro CS courses (that freshmen take). We get points taken off of our projects if we don't meet consistent coding style requirements. So I don't think it's unreasonable of the interviewers to expect a 2nd year to be able to write clean code.
1
Jan 17 '20
All depends on the university you go to and what country etc you are in. Did you see my code? I don't think it's THAT messy. I always comply with my university coding style templates when doing class projects. Different companies have different styles, but I can't be expected to meet the style of a company I have never coded for before if I don't know what their style is.
2
u/indivisible Jan 17 '20
Note though that style/syntax is completely separate from eg code structure, separation of concerns and naming choices. Most companies or projects have their own fixed style guides but that doesn't cover the different concern of how to structure and separate your logic, classes, models, functionalities etc.
You can't be expected to confirm to the specifics of one place's style guidelines (ie bracket placement, whitespace & indentation, line breaks etc) but clean, reusable, obvious code is something separate that can be tested and evaluated and is something you can know beforehand (and something you can practice and improve upon).1
Jan 17 '20
I agree, that's why I did get a bit concerned when white space was mentioned between brackets, as that is a matter of the coding style of the organisation, which like I mentioned somewhere else in the thread, I'd have absolutely no problem sticking to, once I know what that is.
2
u/indivisible Jan 17 '20
As i said, you can't be expected to know their preferences but do note that your code has two different decisions on the subject. Your class and main method use a space before their open braces
{but your other method and loops don't. You've contradicted your own style preference or just don't have one.
It's not a major concern, especially since this is a small example piece done under pressure, but is still potentially worth noting since in projects it's not uncommon to apply "auto-formatting" according to whatever decided upon style guide and having some code that doesn't conform can get auto modified by a future developer working in the class and eg have the side effect of git then "blaming" them for those lines of code or bloating merge requests and/or making code merging more difficult/complicated/noisy later.2
u/chasingviolet Jan 17 '20
Ah, I haven't seen your code so maybe you're right. It does sound like they were being nitpicky but overall at least it's a good lesson learned.
1
Jan 17 '20
I appreciate the advice and response and yes it will be a great learning experience. My code is linked at the top if you care to look but it's no worries if not 😊
4
u/Mitchhhhhh Jan 17 '20
Clean code is not something that was really paid much attention to in my cs program. Important as it is, I feel like that's not something you can reasonably expect a 2nd year cs student to have mastered.
However, I do feel like as a second year compsci student you should know how recursion works and figure out when it could/should be used in simple tasks like this one.
I learned recursion in my first semester and Fibonacci is basically the most common way I've seen the concept introduced.
Alternatively you should have spend a little longer to think about your solution and how you could have improved it, I feel you might have been overly happy to get it working, but if you had spend a bit more time you could have probably seen that an array and indeed the second for loop would have been unnecessary here.
Anyway, don't take criticism too harshly, instead try to learn from it. I've had multiple interviews where I was asked to do some coding challenge and ended up getting no feedback at all, trust me, getting your code picked apart is a 100 times better as it provides you with valuable information for the next interview!
Good luck!
3
Jan 17 '20
Recursion is something I'll definitely be looking at now in my own time, I can't believe the university has left out such a fundamental concept of programming from the course.
Thanks for the advice!
4
u/pokemaster787 Jan 17 '20
I'll share a bit of my own insight.
Straight out of high school I had landed a job working on contract software development (in Java) for a small (think, two people) company. My boss was constantly critiquing my code down to the line, variable names, documentation clarity.
At first, I got annoyed and upset. It was nitpicky. The code worked great. I'd get dozens of comments on a simple program.
Then I realized, it wasn't spite or saying I'm "not good enough." In programming, especially higher level languages, there is always room for improvement. No code is perfect. And programming is not a skill you pick up once and know all of it, you are always learning new technologies, new design patterns, new styles, new documentation methods. No one expects your code to be perfect.
Once I realized he wasn't trying to be elitist (I mean, I wasn't fired so I was doing something right), but instead helping me learn and grow, I learned way faster. When working with code written by others (this will be 99% of a software development career, you are never writing things from scratch in a vacuum) I noticed the exact same things my boss called out in my code. Even noticed it in his code. The reason for the pointers and critiques is that it's way easier for someone else to tell you what could make your code more readable and flexible than you ever could. No matter how good of a developer you are.
I've since moved on to the embedded systems field (while getting an EE degree), and the documentation and programming style he so heavily harped on makes my life and my coworkers' lives infinitely easier. I have almost never had a coworker come ask what my code does, why it's doing anything, or say it wasn't written understandably. I've been told it could be rewritten a certain way for efficiency/code density, or that I could have used a technique I'd never seen to do something better. But your goal as a developer in any organization above one person is not writing code that works, a monkey could do that. You want code that is readable, adaptable, re-usable. And that only comes with practice and getting critique and advice from those more experienced in the field.
Take their advice and use it to better your programming. Don't take it personally. I can point out dozens of little "Oh you could have done this better" in my 60+ year old coworker's code, and I'm sure he could in mine. Just hearing those pointers doesn't make it bad or mean you fucked up. Like I said, no code is perfect, something could always be done better. Don't take it personally, just learn from it and apply it in the future.
3
Jan 17 '20
This is incredible advice. I am of course going to take this as a learning experience. I like criticism because it drives me forward.
My disheartened feeling didn't come from taking the criticism personally, just that I thought maybe I am not up to scratch as much as I though.
3
u/pokemaster787 Jan 17 '20
You're getting there. I know 4th year CS students that would struggle writing the code you did in 6 minutes.
Personally I have a dislike of CS in general as a program, since it teaches very few actual development requirements in my experience. CS courses just want code that works. Real world programming, working code is a dime a dozen. Readable code that you can give to Bob two floors down and he can modify/use without ever needing to ask you for clarification is what (good) software companies want.
If you want to do actual software development rather than computer science (think more, algorithm research and design compared to writing real-world applications), unfortunately you'll just need to do a lot of out of class work on writing professional code. I'm certain your code here would've been an A in a CS class.
I'd start with Javadocs honestly. Documenting code is at least 50% of writing your code, sometimes I document my code before I even write it. Make it a habit to document every class, method, etc. and employers will love you just for that. It's way harder to drill documentation into someone than to enforce a programming style or get their actual code a little more readable. There should be plenty of tutorials online on documenting stuff in-line and generating Javadocs from your in-line documentation.
Also, a final note, a fun (and good) solution to this problem would have been using a Stream! Although you're likely not there yet, Streams are one of the most useful features of Java and I cry every time I write C because I don't have them.
3
u/Jaklite Jan 17 '20
Don't be disheartened, treat it like a learning experience.
I've been on the other side of the interview table and this is one mistake I've made. For coding questions and the like, it's easy to show people all the little things they could have done better. Just keep in mind that it usually comes from a positive place: trying to help you be better rather than trying to put you down.
I'm sure the interviewer didn't mean to make you feel like you did a bad job, they were probably just trying to mentor you a little. Good luck with your interviews!
1
Jan 17 '20
Yeah I don't want it to come across as bashing the interviewer or anything like that, it did seem more like advice, was just trying to see if anyone had similar experiences with this.
Thank you very much!
1
5
u/Kimput Jan 17 '20 edited Jan 17 '20
Seems like I might be going against the popular opinion on this.
I don't think they were unkind, or even harsh, based on the way you are explaining it.
Let me explain: even if you aren't supposed to be able write "clean" code, you should be expecting to be going through a code review and be able to polish off low-hanging fruit such as ill-named functions.
All that being said, I'd probably still hire you as an intern.
Edit:
Didn't see you had posted your code. The code looks "fine", but as a 2nd year CS major I'd almost expect you to solve this using recursion, or in a more elegant solution.
See this as a learning experience to use the entire hour and go through your code.
Also, might be a good idea to add tests to your code! :)
1
Jan 17 '20
I totally understand and I take that code review as a learning experience.
They had spoke about recursion also, but this is an element of programming that I haven't studied yet, both at university or individually.
I guess the university you go to can be a major impactor on what you do know at what stage of your journey.
4
u/pokemaster787 Jan 17 '20
spoke about recursion also
Honestly, 99% of the time recursion is a stupid way to implement something.
Recursion is taught because it's cool and there are a small handful of things you can do recursively efficiently that would otherwise be too expensive or lengthy to do sequentially. There are very few of these cases and 9 times out of 10, recursion is less clear and less efficient. The Fibonacci sequence is actually the de facto recursion introduction in my experience, and it's a terrible use of recursion.
3
u/indivisible Jan 17 '20
Recursion certainly doesn't have as many real-world use cases as education about recursion may make it seem but it's still an important subject/pattern to know. It teaches quite a bit about algorithms and stacks without getting too involved and overly complicated which even of you never write a recursive solution for anything is still valuable knowledge to have for other cases/solutions. It's just one of those foundational or pillar topics in computer science that everyone should understand but that not many solutions will require.
3
u/pokemaster787 Jan 17 '20
Right, recursion is important to learn of and know. I just think many new programmers tend to learn about recursion and use (or try to use) it in scenarios where it's not only complicating the code more, but making it less efficient as well. I just wanted to emphasize that while recursion is usually an option, it is rarely the best. Particularly in this scenario, where the Fibonacci sequence is 99% of CS courses' introduction to recursion (in my experience) and simultaneously one of the worst times to use recursion. Definitely it is important to learn about it, the consequences of overpopulating the stack, method call costs, etc etc. However.
I particularly like the saying "A programmer has a problem and thinks 'Oh I know, I'll use regular expressions!' Now he has two problems." I feel much the same way about recursion. A very important tool, but very niche in its useful applications at the end of the day.
2
u/indivisible Jan 17 '20
A good way to put it might be that "Recursion isn't the best solution for a Fibonacci sequence generator" but that "Fibonacci sequence generation is a good example case for a recursive method". The second reason better explains it's common use in education.
3
u/Kimput Jan 17 '20
Yeah, absolutely.
I studied recursion my second semester, together with functional programming. All that being said, you rarely use it in the wild.
But the Fibonacci sequence is a textbook example of when to apply it.
5
u/nutrecht Jan 17 '20
Your interviewer was in no way harsh. Your code just has a bunch of 'beginner mistakes' most beginners make, and he was just pointing these out.
You really need to get used to this because code reviews are a thing. And the most important thing you need to learn is to not take criticism so personal. Everyone receives it; it's how we improve.
Unfortunately you're getting a lot of "the interviewer was a dick" type comments from people who are clearly not employed as developers. I mean, "would slap them in the teeth" should make that obvious.
1
Jan 17 '20
I didn't say the interviewer was harsh I just wanted some advice on the matter because this is the first code review I've really had.
I also didn't take the criticism personally as such, just felt disheartened in that my own skill level may not be up to the task yet. That's all.
Also, most of the comments I have been reading are in agreement with you, apart from a select few. A lot of people I think have misinterpreted what I was saying here. I am not bashing the interviewer, just trying to see if things are this are commonplace in the interview circle.
Thank you for your feedback.
1
u/nutrecht Jan 17 '20
Funny enough you're doing the same thing here. You asked if this was normal because you were disheartened. I'm telling you you should not be, because it's a great learning experience. And pretty much all you reply to me and others is that you're not trying to bash the interviewer.
That's not what people are telling you. You focus, again, on the idea that you're being critiqued instead of looking at what people are saying and having an actual conversation about that. It's not a good habit and something you should be aware of.
-1
Jan 17 '20
You said "The interviewer was in no way harsh", my response was that '"I'm not bashing the interviewer".
Your next point was not to "take criticism personally", and I responded to that with "I didn't take it personally... my own skill level may not be up to the task".
Your 3rd point was about all of the other comments about "interview was a dick", which there's maybe 1 or 2 in this whole thread. I directly responded to that again saying "most other comments are in agreement with you".
Each paragraph I wrote was a direct response to the corresponding paragraph written by you. So maybe you should read what I have responded to other people, because in several places throughout this thread I have said how I was going to use this as a learning experience. My responses are appropriate to the comments that have been written.
3
u/indivisible Jan 17 '20 edited Jan 17 '20
They were speaking about all your comments not just the one in reply to them I believe. And also, without trying to be harsh, just analytical, I somewhat agree with them. You are only trying to defend why you made the decisions you did but it does read a bit like you are defaulting to defence first and only taking the feedback once it's been supported by a majority view. It does read as quite argumentative in places.
As you say yourself, you're inexperienced (and nothing wrong with that, we all were at some point) but instead of accepting your peers critiques and perhaps asking for clarity or more depth, you've jumped to defending or excusing/explaining your practices first. The more experienced people replying to you, while not all have written long answers with supporting references or examples are almost all correct in the things they're pointing at that could be improved on.
As said elsewhere here, don't take criticisms of your code personally and even sometimes accept that you need to take more experienced peoples' advice to heart even if they haven't explained all the reasonings behind why yet. There are times and cases where the "right thing to do" isn't always obvious or even decided at the scope or level you'll be working in.If it's just a case that the tone of your responses is only coming across that way but was never intended by you then that's just the internet. It can be hard to portray or perfectly see the lilt on what someone is saying compared to real life communication. Maybe take that as another learning point to be a tad clearer with your wording or just *slower to jump to conclusions about others' intent or their own text's lilt.
-1
Jan 17 '20
I'm sorry that I am coming across as defensive I guess it's just how some of the stuff I am saying reads. I really am not trying to be defensive, I am merely just trying to explain my thought processes behind things, but maybe I'm not portraying that correctly.
I may get defensive in some cases where someone who has commented has made a presumption that something I have said was "defensive" or for example someone said "It doesn't matter how much experience you have, if your product is bad, it's bad". Now of course that statement is true but it isn't relevant to my post and it isn't helping anybody. But to go back to your point, maybe I am misinterpreting these people too, sometimes it is just difficult to see exactly what someone is saying by reading text.
For example, if you see my initial response to your code review, I feel that I have shown gratitude saying things like:
"That is useful information on the scanner.close() method, as I did not know System.in closes that automatically.
I will go on to learn from this experience as I do from every experience, it just leaves me a little frustrated that things that interviewers expect you to know like recursion aren't even covered at my University to this date."
or:
" Thank you very much for this constructive feedback. "
I don't feel like i'm being overly defensive, if it comes across that way then I apologise.
3
u/indivisible Jan 17 '20
To be clear, I didn't read anything in the exchanges we've had here as defensive but I've been pretty verbose and polite so you responded in kind. Others though that replied to you, and you to them, that were shorter or more direct in their critiques got your defensive responses. Could some of them have been more polite or clear? Sure. But do they have to be? Not really.
All the feedback here, positive and negative, long or short, is of some use to you. People are spending some small portion of their time reading your post and code to offer feedback. Even if it's not written in a way you'd like to see it you should still accept it for what it is, free advice, freely given. You replying defensively or belligerently (warranted or not, intended or not) isn't helping anybody, possibly dissuading some and just not needed. As said elsewhere too, there are some personality types that development attracts that can be safely and frequently need to be ignored. They can't ever be avoided entirely, you'll just need to learn to desk with them, brush off any of the bad attitudes and see if there's any nuggets of wisdom hiding under the mud slinging.
/shrug-1
Jan 17 '20
I don't really know what else to say man, I'm not trying to be defensive just explain myself.
"You replying defensively or belligerently (warranted or not, intended or not) isn't helping anybody, possibly dissuading some and just not needed."
If it isn't intended to be defensive, then it is not me being being defensive. If someone interprets it as defensive, I can have no control over that.
I appreciate anyone taking the time to read this post and give me feedback, however that doesn't mean that I shouldn't stand up for myself if someone is coming across as rude, or if i disagree with someone. I am allowed to have a discussion. I don't think there is anything wrong with disagreeing with certain points of view.
"People are spending some small portion of their time reading your post and code to offer feedback."
I am super appreciative of that, but that is also their choice to do so, and your wording makes it seem like I should be feeling indebted to them.
3
u/indivisible Jan 17 '20 edited Jan 17 '20
No, not indebted but maybe more outwardly appreciative of (?) even to those replies you "read as offensive". One or two I saw were merely pinpointing something out but you responded differently.
We're getting pretty off topic here and into the area of fundamentally how text comes across online so not really worth going in to very deeply imo just that you may need to either be a little more lenient with the attitudes you ascribe to what you're reading or, learn to have a thicker skin when putting yourself out there like this. There's always one or two of "those types" that'll show up to any online discussion to troll or derail things etc, you might just need to learn to handle then better than going head to head with them. And even overtly direct or abusive people/reviews can contain useful feedback. imo just thank then and move on, never worth getting overly invested/engaged with even if you are "in the right".
0
Jan 17 '20
I guess so, it's just hard in the moment to thank someone for something that comes across as an attack I suppose.
→ More replies (0)
8
u/i_like_outer_space Jan 17 '20
As a senior developer if anybody on my interview panel pointed out that in someone's interview code I would slap them in the teeth. just about every interview I've had in my life is pseudo code and it's meant to get the point across quickly because interview time is precious.
3
u/nutrecht Jan 17 '20
As a senior developer if anybody on my interview panel pointed out that in someone's interview code I would slap them in the teeth.
If you as a 'senior developer' did stuff like:
long [] fib = new long[n]; fib[0] = 0; fib[1] = 1;It would be a really short interview. His interviewer was just pointing out some issues with OP's code so he would learn from these mistakes.
1
Jan 17 '20
Can you please give any advice as to how I could clean up those 3 lines to make it better?
I'm not too sure what I've done wrong but I'm sure there's something there
2
u/nutrecht Jan 17 '20
There's just no reason at all to use an array there. Just use two long vars.
1
Jan 17 '20
Oh yeah I know they pointed out the use of an array in the interview. I thought you had meant there was a problem with how I was declaring and filling my array. My bad.
2
u/indivisible Jan 17 '20 edited Jan 17 '20
Objectively you could still improve in those lines without changing the implementation/approach you did.
Firstly, and a relatively small thing,
long[] arris generally preferred over yourlong [] arrand certainly more thanlong arr[].
The compiler will accept any of those formats as the same thing but the first is the (almost) universally accepted way to write it. Java being flexible on it is a hold over from it's origins of trying to appease or make life easier for developers with experience with C's syntax.
When writing code in teams or at an enterprise or professional level, the aim is to make the code readable for other developers first and foremost with compiler or performance concerns taking a back seat a lot of the time. Studies shore that in the long term it helps with the speed people working on it can go and the fewer bugs that are likely to be produced.Secondly, and maybe up for debate, there's no need to set the first element to zero, it already is zero since that's the default value of every element in the array on initialisation according to the Java specs in primitive arrays.
Explicitly doing it though does show the obvious developer intent that it should be zero so there's an argument to have it even of it's a "no-op" or wasted instruction.2
Jan 17 '20
I see. Is there any particular reason why the long[] is preferred over long []? I suppose now that I think about it, it is a bit clearer to read. Keeping the brackets right next to the variable type leaves no room for confusion.
That's a great point about the wasted fib[0] = 0; I never even thought of this as being already assigned to 0. I will be more aware of this next time.
2
u/indivisible Jan 17 '20
It's about both keeping the type declaration succinct but also being as predictable as possible. There's a general rule known as the "rule of least surprise". It's better and clearer that developers know to look at the type itself for an array declaration so that they're not "surprised" later when a variable they took as singular when they were scanning through the code turns out to be an array that their eyes glanced over or was defined after the variable name that they never even read since they didn't care much about that name or scope at the time.
It's just both cleaner and clearer to do it this way and leads (again) to fewer mistakes about what the code is doing long term.1
Jan 17 '20
I understand where you're coming from, I'll definitely take this on board. It's small things like this that just would never be covered as part of a course, and can only be learned by having a conversation with those experienced in the field.
1
u/i_like_outer_space Jan 17 '20
That's not what I'm saying. I'm saying if I was the interviewer. Also taking into consideration he's a two year CS student.
2
2
3
u/Who_The_Fook Jan 17 '20
I'm not really in agreement with most of the comments here, or the interviewers for that matter. Your naming scheme was very descriptive and described it perfectly. I'm not sure what the beef is from them. Seems like unnecessary nitpicking, at least for naming and ESPECIALLY for adding a space between ) and {. That varies depending on organization and their personal standard, so it shouldn't be something they judge you on. I can see the array comment being valid though.
3
u/Java_Junior Jan 17 '20
You completed the coding task in a fraction of the time allotted to you. That is huge. Their complaints about syntax are basically irrelevant, and their suggestion about data structures is an honest learning opportunity. You should feel victorious right now, not embarrassed
3
Jan 18 '20
"There’s a bright side: if someone asks you to change something in your app, that means someone still cares about it." Alexander Shvets on Dive into Design Patterns
2
2
Jan 17 '20
Just thank them for the feedback. I agree that it was a bit harsh, especially since there didn't seem to be any clear direction other than "print out the result", but yeah. Just take the advice and stay humble. It's also your first interview, and know that they also probablu expected you to be pretty green. Hang in there!
2
u/Delusional_Sage Jan 18 '20
There will always be people who think you could have implemented a solution better, just be appreciative of opportunities to learn.
1
u/SuperFluffyPunch Jan 18 '20
Guess I'm the only one who thinks that the criticism is a little strange.
You were given a task within a time frame. Obviously your code won't be clean and elegant. The code works. That's all that matters. Sounds like the interviewer was being a prick.
0
Jan 17 '20
[deleted]
2
Jan 17 '20
I did know before hand what it was but it was also explained at interview stage so I wouldn't worry about that my friend.
Thank you for the encouragement!
0
Jan 17 '20
[deleted]
1
Jan 17 '20
I was able to use https://repl.it/languages to write the code :)
I then just had to copy and paste that into an email to the employer when the code review was done.
1
0
Jan 17 '20
[deleted]
4
Jan 17 '20
Yeah I guess everyone has a different coding style but I would have no problem adapting the styles of a particular company.
0
Jan 17 '20
[deleted]
1
Jan 17 '20
My code is now in the main post if you want to take a look :)
3
u/indivisible Jan 17 '20 edited Jan 17 '20
As others are saying, don't be offended or disheartened by the feedback but also don't just brush it off lightly either.
In large, mature projects method and variable naming is a very important aspect of programming that should impart as clearly and precisely as possible the use or intent of whatever code in question.
Often it can mean the difference in a future developer working on that code (including future you) between knowing the exact purpose of some code quickly or making a simple mistake about the implementation, intent or side effects leading to bugs. It also may cause wasted time in having to read more code than otherwise necessary to determine exactly what's going on within the ambiguous named methods/variables which in the long term adds up and is wasted money.As for your posted example code (even though it appears edited from what you submitted to them) there are other things I'd point out or talk about along with just the possible naming choices which in this case, I'd personally see as not so bad with "fib" being just a method scored variable and "printFibonacci()" actually doing printing.
Since you are generating the sequence in its entirety before looping it to print, you could split the sequence generation and the printing into different methods.
Have oneint[] generareFibonacci(int)method and avoid printSequence(int[])which makes it easier down the line to reuse either method for other purposes.For the bounds given (1-100) holding the values in an array is probably fine since it has a sane max length it could ever be. However, depending on the specific wording or specifications given to you, maybe there'd be a need to have an much longer sequence generated or be able to start from an element other than the first.
Performing your input validationif (1 >= n >= 100)immediately before your sequence generation hard codes its bounds and limits future reuse again. Doing the validation as soon as you read the user input makes more sense. That way you don't need to even start the sequence generation unless you have good input first and keeping the validation beside where you read the inputs makes it easier to spot and edit later on.Closing your scanner. While it is usually good practice to clean up any resources, buffers or handles you open,
System.inis a special case and an exemption normally. It's not typically recommended to manually close System.in (which your call toscanner.close()will cascade to do) since that makes it unavailable for the rest of the application's life. In this example it's not actually a problem but can have knock on effects in larger code bases or even by introducing outer loops later (what of you had to generate 2 sequences?).
The JVM will automatically manage any streams that it opens when it exits and System.in is one of those so better to leave it as is and the JVM will take care of closing it later. If you want to clear your own usage you could null your scanner if you wanted to free it up without triggering the close ofSystem.in.Lastly, your printing of the resulting sequence leaves a trailing comma (
", ") after the last element. You could reorder your instructions, manually trim the final chars, add some conditional logic or just modify your loop to eliminate the unnecessary final print.
You could also instead use a StringBuilder (which allows for modification and has generally lower overheads than string concatenation in Java) and only make one print call after generating the entire String sequence.That's going a bit deeper than maybe required for reviewing just this small piece of code and while functional for what you say the requirements were there's definitely still room to improve upon it.
As I started, don't take any code review criticism (from them, me or any other developers) personally. The stereotype of unsocialible nerds may not be as high as some think but it is non-zero so some may just be more direct than they might potentially be.
Since development is STEM field, an area of science or engineering, where accuracy and clarity is much desired along with criticism or outcomes of work having little to do with the person performing it. In the end the state of the code matters more than any one developer or anyone's ego. It can seem harsh at times but is very rarely accompanied with any actual offensive intent.
See also: the love/hate for StackOverflow or Linus Torvald's code reviewing styles (past and present).1
Jan 17 '20
Thank you very much for this constructive feedback.
Also, the code has not been edited from the interview, this is exactly the code I had written on the day. I had to email the code to the employer so I took the code from that email and pasted it straight into pastebin. In terms of the array size (1-100), that was a constraint that they has laid out in the challenge.
I understand what you are saying too about the input validation and I can see why that would be more applicable right after the user input. I had originally thought of implementing a while loop here to ensure correct input, but I thought that may be outside of the bounds of what they were looking for so I didn't want to push it too far.
That is useful information on the scanner.close() method, as I did not know System.in closes that automatically.
I will go on to learn from this experience as I do from every experience, it just leaves me a little frustrated that things that interviewers expect you to know like recursion aren't even covered at my University to this date.
I'm left to think: What else am I going to be expected to know that I haven't yet learned about?
0
Jan 17 '20
[deleted]
-3
Jan 17 '20
Of course it matters how much experience you have. An amateur boxer with 1.5 years experience isn't going to step into the ring and take out the heavyweight champion.
Don't be naive.
1
u/chasingviolet Jan 17 '20
lol but being expected to write clean code is not "taking out the heavyweight champion", that's a basic that people are taught in intro to programming or intro to software dev.
3
Jan 17 '20
More experienced programmers write cleaner code...
Did you even look at my code? Not like I had brackets and colons flying all over the place, there was structure.
Not all universities teach the same concepts in their Intro to Programming modules, maybe you're lucky you got a good one..
0
Jan 17 '20
[deleted]
-3
Jan 17 '20
You didn't provide any support or advice though. You just told me that I'm not good enough. That's not advice. There was no advice on how to improve. There was no advice on resources for learning to write cleaner code.
All you basically said was, 'If you're bad, you're bad.".
0
Jan 17 '20
[deleted]
-1
Jan 17 '20
I mean, I interviewed yesterday and they said my answer was on similar level to the others they had interviewed. I'm yet to be accepted or declined. I read some of your responses to other people's questions and you just have a chip on your shoulder. It's quite obvious.
Please tell me where the advice was in your original comment and I'll resign.
Thanks :)
0
Jan 17 '20
[deleted]
-1
Jan 17 '20
That's twice you've avoided the topic now, because you realise that you didn't actually provide any useful advice.
I didn't ask you to care about me and nor do I need you to
Have a nice day :)
29
u/dankallin Jan 17 '20
I would advise you to try and take a step back from the way they commented on your work, and instead try to hear the msg. Sounds to me like the comments basically said "This isn't as readable as it could be".
So, if you don't get this - then take from it that readability is important. Singular purpose is also important.
At my work we're working in a 5 year old code base and it has NOT ever given a thought to readability or posterity. And let me tell you it sucks so flippin much. So, while they probably could've shared their feedback less harsh, their obnoxiously made point is kind of valid.
Don't let em get you down though! Keep applying and keep coding, everyone faces setbacks!