So, I have been looking for a job for quite a while now, and have had some interviews. Thus far, I have not been successful, though.
I just had an interview, where I was asked to solve some things during the interview. Here are some of the questions that I didn’t have an answer to, from the top of my head.
“In Bash
, change mode of all jpg-files in the current directory, and sub directories”.
Here, I was first thinking about how to setup the for
-loop in bash. There is the do
, and done
, and somewhere, you need a semicolon.
I also started to think about using find
, but was not sure if I needed the flag in xargs
to limit the output to one entry per line. While I was contemplating, the interviewer asked how much I had done in Bash
, and I said, I mostly did small build scripts. And then he asked about Makefile
, so we skipped the first question.
I later checked the solution I was starting to form in my head:
find . -iname *.jpg | xargs chmod 600
That would have worked.
“What does .PHONY
in a Makefile
mean?”
I have seen it often, but never looked it up.
Now, I have found that it is a directive you put in a Makefile
, that is always dirty, thus is always built. This is mostly used for clean
and all
. A Makefile
always has a target, and clean
and all
are used for cleaning up the build (remove all built binaries and libraries), and to make all projects. If you then have a file in the directory that is called clean
or all
, it becomes ambiguous for make
, if you want to build the file clean
or if you want to clean up the build. That’s why you setup a .PHONY
directive.
“How do you combine two lists in Javascript or Python”.
This, I should have known. But I guess it is something that I missed by not doing a proper course in Python, or I have simply forgot it. I hate it when I forget the elementary things. I don’t know how often I have to lookup “Hello world” in languages I have used before, because I have forgotten how to start a simple project, or how to output text to command line.
The more detailed question:
“You have:
a=[1,2,3]
b=[4,5,6]
How do you create
c=[1,2,3,4,5,6]
?”
I quick-and-dirty-solved it in Python like this:
c=[]
for x in a:
c.append(x)
for x in b:
c.append(x)
This was not an acceptable solution, and we broke off the interview at this point.
When did some searches. I saw, I should have simply tried the +
-operator:
c=a+b
In other languages:
In Javascript, you can use concat
.
c=a.concat(b);
In C/C++, first C-arrays:
//How do you concatenate c arrays?
int a[3]={1,2,3};
int b[3]={4,5,6};
int c[6];
// You actually don't need to specify the size of the
// array,
// if it is initialized with the {} notation,
// the compiler can infer it:
int d[]={1,2};
//Need to loop through a and b to fill c, and for this,
// need to
// specifically know the sizes of the arrays
const int size1=3;
const int size2=3;
for(int i=0; i < size1; i++)
{
c[i] = a[i];
}
for(int i=0; i < size2; i++)
{
c[i+size1]=b[i];
}
In C++:
// In C++, you should use std::vector
std::vector a_vec;
a_vec.push_back(1);
a_vec.push_back(2);
a_vec.push_back(3);
// In C++ 11, you can use the array initialization as
// well:
std::vector b_vec = { 4, 5, 6};
std::vector c_vec;
c_vec.insert(c_vec.end(), a_vec.begin(), a_vec.end());
c_vec.insert(c_vec.end(), b_vec.begin(), b_vec.end());
It is worrisome, that my memories of some of the basic things are so sketchy, I need to shape up, to call myself senior in any language. Maybe I should stop looking at more different languages (I am currently working my way through SICP - Structure and Interpretation of Computer Programs), and focus on some languages that I would like to work in.
Other resources that deal with what it means to be "Senior Developer": The programmer competence matrix.