I'd like to see Clean code:
Clean code: Software code that is formatted correctly and in an organized manner so that another coder can easily read or modify it.
That means:
- Functionality - Some simple bits of functionality that are non-trivial (a bunch of getters/setters wouldn't show that you know anything)
- Consistent, clean style - Popular or at least common casing, indentation, spacing and bracket styles
- Good Naming - Quality names - don't use
iunless it's the only increment value. Don't use nonsense variable names. - Other attributes of Clean code - Good practices on error-checking, conditions, loops, convenience methods or utility methods, and good separation-of-concerns (between methods). And this is a good time to be 100% DRY - no repetition!
You want to send them something that is complex enough to be interesting but clean enough that a good developer can nearly immediately understand what it's doing.
Some of the comments above seem concerned with how easily this could be faked.* If you want to protect against this, then possibly send a quick description of the purpose and history of the code in the email.
* At the very least if the interviewer asked about past projects up front, then asked you for a sample from this project, and asked what required you to write it or how it evolved, I think the process would be pretty liar-proof. I think most candidates who would lie are going to show problems in other areas, anyway.
Answer from Nicole on Stack ExchangeI'd like to see Clean code:
Clean code: Software code that is formatted correctly and in an organized manner so that another coder can easily read or modify it.
That means:
- Functionality - Some simple bits of functionality that are non-trivial (a bunch of getters/setters wouldn't show that you know anything)
- Consistent, clean style - Popular or at least common casing, indentation, spacing and bracket styles
- Good Naming - Quality names - don't use
iunless it's the only increment value. Don't use nonsense variable names. - Other attributes of Clean code - Good practices on error-checking, conditions, loops, convenience methods or utility methods, and good separation-of-concerns (between methods). And this is a good time to be 100% DRY - no repetition!
You want to send them something that is complex enough to be interesting but clean enough that a good developer can nearly immediately understand what it's doing.
Some of the comments above seem concerned with how easily this could be faked.* If you want to protect against this, then possibly send a quick description of the purpose and history of the code in the email.
* At the very least if the interviewer asked about past projects up front, then asked you for a sample from this project, and asked what required you to write it or how it evolved, I think the process would be pretty liar-proof. I think most candidates who would lie are going to show problems in other areas, anyway.
When I was looking for work, I solved a bunch of ACM programming contest questions, in several different languages, and use those for code samples since then. I think they made good code examples because:
- They solved challenging problems
- The problem didn't require a huge amount of context, plus its easy to get the questions
- The code written doesn't have any IP risk associated with it.
- Each problem can reasonably exist in a single file, and often not extremely long, so it should be easy for anyone to compile, and test your solution, and can use the test data from the questions.
- Shows you can break down a complex problem into smaller pieces.
- If you are asked about how any aspects of your solution works, it gives you a great opportunity to demonstrate you know what you are talking about, especially so if it's many years old but you can quickly decipher whats going on.
And then, the code you create should be clear, consistent, easy to read, and easy to understand.
And lastly:
- It's worth solving them just for fun, and is good practice.
Advice for writing coding samples in R, or any examples?
What do employers really look for in "sample code"?
Where do I write my code?
You might want to be more specific on what website you're on and what language you're learning. That will make it easier for people to point you in the right direction.
Not knowing what you're working on, I'll give you a general overview of how things work.
Some languages are interpreted while others are compiled.
Interpreted languages use interpreters to run the program line by line. Javascript (JS) is one such language (and one of the most popular languages and considered the language of the internet). Your browser is an interpreter. So all you need is a text editor where you'll write your program (even notepad works) and a browser. I suggest downloading Notepad++ for free. It's a good text editor that allows the downloading of several plugins to format your program (among other things). Just write your code, save it as a .js file (literally write the program's name followed by .js when first saving the file), and click on the saved file. Your browser will open and interpret your language. Note, you will want to also learn HTML. It's a mark up language that provides the web page data structures which JS interacts with to make more dynamic. It's neither interpreted or compiled. The JS can still work on its own because you can literally build the html, but having your JS render the entire dom is not a standard part of the industry since it's slow.
In contrast, compiled languages need to be compiled before being run. This means some language a programmer is writing is converted directly to machine code so that the processor can execute the commands in the program. Programmers made these compiled languages, because machine code is made up of binary (0s and 1s). Writing out anything in machine code would take way too long and be error prone since it's not something people can translate instantly like a compiled language which uses your own language (i.e. English).
C# is an example of a compiled language. It requires more applications to be downloaded than JS. A browser may also be required if the program you're writing is a web application whereas a desktop application doesn't need a browser. A text editor and a compiler are required. You can use Notepad++ as your text editor if you download the plugin to format c#, but text editors don't compile compiled languages, so you'll need something to compile your program as well.
The hard way is downloading the .NET framework and using the command prompt to run a command that will compile your program. If you have windows, the command prompt an application called Command Prompt that comes with Windows.
An IDE (integrated development environment) is the better way to write compiled language applications. It includes the compiler and text editor along with a lot of other features that make development easier. There are community editions of Visual Studio, but Visual Studio Code is also a good choice that is free. There is a learning curve, but because the IDE provides a graphical interface with buttons and menus, it's easier than learning commands and writing them out in a command line.
It also includes a debugger, which allows you to put a breakpoint in your program and step through its code. This means the point in code which you put the breakpoint (the IDE's mechanism to pause the code at a particular part while it's being run), you'll be able to click a button to either step over the code line by line or step through code from one break point to another. That's more than you need to know now, but you will need to learn it eventually so starting with an IDE is ideal if you want to become a professional programmer.
If the website you're on has no information on installation and how to write a program in the language you're learning, you should probably google for a beginner tutorial on that language. Beginner tutorials usually will include any type of installation required.
Good luck!
More on reddit.com