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 i unless 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 Exchange
🌐
Google
developers.google.com › technical writing › creating sample code
Creating sample code | Technical Writing | Google for Developers
Sample code should be short, including only essential components. When a novice C programmer wants to learn how to call the malloc function, give that programmer a brief snippet, not the entire Linux source tree. Irrelevant code can distract and confuse your audience.
Top answer
1 of 7
17

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 i unless 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.

2 of 7
9

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.
Discussions

Advice for writing coding samples in R, or any examples?
Just do a project or two using some public data set and then you can share your code on Github, personal website, etc. I use baseball data, but it doesn't really matter. More on reddit.com
🌐 r/datascience
2
3
April 29, 2023
What do employers really look for in "sample code"?
I look for code that wouldn't absolutely horrify me if my coworker checked it in. Things I want to see: Well chosen variable and function names. Comments for code which is not self-explanatory. Correct algorithm and data structure usage. Since this is gamedev I want to see an eye for performance implications as well. Avoid dynamic memory allocation when possible, for example. Bonus points for very clever problem solving or going the extra mile, so long as the code is still understandable and there's a tangible benefit. For example, a multithreaded implementation of an easily parallelizable algorithm is neat and makes you stand out. Things I don't want to see... Comments everywhere for code which is self-explanatory. This is typically indicative of novice programmers. "Clever" approaches which make the code hard to understand or maintain, particularly if there is little or no tangible benefits. Writing something in assembly language is a good example of how to make yourself look worse by trying to show off. (If you're going to do this you'd better leave a good comment explaining why it is an improvement over what the compiler emitted, and include a C++ implementation as well.) Inconsistent styling. This indicates a lack of attention to detail, consideration for your coworkers (programmers are naturally a little OCD about code styling), or that you copy and pasted code from the internet. Any hint that you don't fully understand the code you wrote is a massive red flag. Cargo cult programming is pretty easy to detect. In general, when looking at a code sample, nobody actually cares how complex the problem you're solving is. We want to see code samples to know that you can actually write sane and readable code. Your problem solving skills will come out in the interview(s). Alternately a lot of studios will give you a programming test instead of asking you to solicit your own code. So, the last thing you need to worry about is having a body of complex code in the public domain. More on reddit.com
🌐 r/gamedev
43
41
January 10, 2013
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
🌐 r/learnprogramming
192
1056
October 29, 2021
Fellow developers, where do you place your project source codes?
I put all my projects under /home/{username}/projects/ and bookmark the folder in the file manager so it's 1 click away if I need to open it via the UI (for example from VSCode). This of course it's just what I do, but you're free to choose what works best for yourself. Edit: by "all my projects", I generally mean, for each project, a folder which is a git repository for that project. So inside my projects folder i have project1, project2, ..., projectN, where each of them is a git repository. More on reddit.com
🌐 r/pop_os
46
35
August 3, 2022
🌐
Alley
alley.com › home › news › how to select and prepare great code samples
How to select and prepare great code samples - Alley
August 21, 2023 - Is it performant? Is it secure? Is it over- or under-engineered? Would I deliver this code to a client? Code samples are an extension of your résumé. Be mindful of that and prepare them with as much care as your résumé, cover letter, and the rest of your application packet.
🌐
WebPlatform
webplatform.github.io › docs › WPD › Manual_Of_Style › Code_sample_best_practices
Code sample best practices · WebPlatform Docs
Comment your code well. It can be frustrating to have to determine what a sample is doing at any one point. For example, see http://code.webplatform.org/gist/9011914. Keep it easy to scan the code.
🌐
Developer-advocacy
developer-advocacy.com › write-excellent-code-examples
Write excellent code examples - The Developer Advocacy Handbook
So instead of starting by reading the docs yourself, check what the tool can do and look for a problem you always wanted to solve that this technology can help with. Then solve it using the product and explain what you've done as the code example. This is also an excellent way to check the ...
🌐
Medium
mmarcosab.medium.com › an-example-of-a-guide-of-good-practices-to-write-code-66621118c27
Sample best practice guide for writing code | by Marcos | Medium
February 24, 2023 - If logging your application’s actions, pass enough information to log the error in your catch. Returning null in methods is bad, but passing null as a parameter is worse. Work with Optional. Third-party codes — Write tests for third-party sources, so when you change it’s easier to understand what was changed.
🌐
Medium
medium.com › flutter › writing-a-good-code-sample-323358edd9f3
Writing a good code sample. Authoring a good code sample is hard… | by Brett Morgan | Flutter
August 23, 2021 - After code formatting, the next step is enforcing a good set of lints. For Dart, I strongly recommend investigating the lints package, and for Flutter I likewise recommend the flutter_lints package. To make sure the lints pass in the CI pipeline, add the following command: ... Tests. Oh so many tests. Unit tests, integration tests, and for Flutter we also have Widget tests. Tests are great for samples, as the tests communicate intent of how a piece of code is intended to be used.
🌐
DigiPen
digipen.edu › showcase › news › ellen-beeman-writes-how-to-guide-code-samples-for-programmers
Professor Writes the How-to Guide on Code Samples for Programmers | DigiPen
November 3, 2020 - Beeman, of course, would go on to join the DigiPen faculty in 2014 to help teach new generations of aspiring game developers how to chart their own paths to career success. Though Cleveland’s code sample has been lost to time, the memory lives on in part through a new book titled Code Samples: The New Professional Programmer’s Guide, authored by Beeman and filled with tips and best practices on how to impress prospective employers through well thought-out code snippets.
Find elsewhere
🌐
WordPress
ffeathers.wordpress.com › 2013 › 12 › 21 › how-to-write-sample-code
How to write sample code | ffeathers - WordPress.com
February 16, 2014 - Technical writers often need to create sample code, to illustrate the primary use case of an API or developer tool, and to help developers get started quickly in the use of the API or tool. Here are some tips on how to go about creating that code. I've jotted down everything I can think of.…
🌐
Jvns.ca
jvns.ca › blog › 2021 › 07 › 08 › writing-great-examples
Write good examples by starting with real code
July 8, 2021 - The basic idea here is to start with real code that you wrote and then remove irrelevant details to make it into a self-contained example instead of coming up with examples out of thin air.
🌐
Blogger
grumpytech.blogspot.com › 2010 › 02 › how-to-prepare-code-sample.html
Grumpy Tech Guy: How to prepare a code sample
February 25, 2010 - Your code has enough comments, and that the comments follow the format recommended for your language (for example, in Java the comments should follow the JavaDoc rules). The comments should include one comment per code unit (module, class etc), and one comment per function (method etc.). Reviewer should be able to easily understand the purpose of the code and get some idea how the code is supposed to work.
🌐
DEV Community
dev.to › attkinsonjakob › how-to-send-code-sample-when-applying-for-a-job-2b3m
How to send code sample when applying for a job? - DEV Community
May 9, 2020 - I would recommend you try to have a couple or so personal projects on GitHub to increase your chances in the long run to land interviews and jobs. ... This is really difficult! A lot of companies expect that developers (even ones with years of experience) provide samples of code they didn't get paid to produce.
🌐
Pete Holiday's Blog
blog.pete.holiday › 2015 › 07 › compiling-the-best-possible-code-sample
Compiling the Best Possible Code Sample | Pete Holiday's Blog
May 12, 2018 - I put together a sample code sample, which you can check out on GitHub. Feel free to do all of the GitHub-y things — forks, pull requests, issues, etc. — if you see anything that ought to be changed. It took me a couple of hours to put that together, which is just to say that it’s not a trivial endeavor. Prepare ...
🌐
Atomic Spin
spin.atomicobject.com › job-application-code-sample
Pick the Perfect Code Sample for Your Next Job Application
June 11, 2018 - The Do's and Don't's of picking a good code sample for your next software developer job application (at Atomic Object or elsewhere).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › MDN › Writing_guidelines › Writing_style_guide › Code_style_guide
Guidelines for writing code examples - MDN Web Docs | MDN
March 10, 2025 - This article describes code style and formatting guidelines for code examples on MDN Web Docs, irrespective of programming language. For guidelines about prose and other content, see the writing style guide.
🌐
I'd Rather Be Writing
idratherbewriting.com › learnapidoc › docapis_codesamples_bestpractices.html
Code samples | I'd Rather Be Writing Blog and API doc course
1 month ago - Specifically, pages with less than 4 sentences before code samples performed twice as well as pages with 11 sentences before code samples. Jarod Reyes explains: It’s a mental block more than it is not being able to see code. It tells a developer that this page has a lot to say, and that they have a lot to do.
🌐
Google
developers.google.com › style › code samples
Code samples | Google developer documentation style guide | Google for Developers
Introduce code samples with a sentence or paragraph, ending with a colon if directly preceding the sample, or a period if there's intervening material. Refer to the relevant code style guides, such as Google's or project-specific ones, for ...
🌐
Codecademy
codecademy.com › forum_questions › 4fc8add1ce770c00030497f4
Example code | Codecademy
My preference was to use a while loop for the PrimeCheck function, the basic code is here in the rectangle. The exercise accepted my code but in the next exercise had replaced it with a for loop, no point fighting it.
🌐
Improving Software
improvingsoftware.com › 2009 › 04 › 10 › the-programmers-guide-to-getting-hired-the-code-sample
The Code Sample (The Programmer’s Guide to Getting Hired) | Improving Software
May 16, 2009 - Know thy code: You should know the code you submitted backwards and forwards, have some ideas about other approaches you could have taken, be ready to optimize it, and talk intelligently about all of the technologies you used. The code sample is fodder for under-prepared interviewers who are digging for something to ask about.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › MDN › Writing_guidelines › Code_style_guide
Guidelines for writing code examples - MDN Web Docs - Mozilla
October 20, 2025 - This article describes code style and formatting guidelines for code examples on MDN Web Docs, irrespective of programming language. For guidelines about prose and other content, see the writing style guide.