Slashdot Mirror


Short Coding Projects?

sapped asks: "Whenever somebody advocates a new programming language for you to try, they will usually suggest writing something in it that will take you an hour or two to code, so that you can get a feel for it. My problem is that I tend to go from extremely trivial ideas straight to stuff which will keep me busy, for at least a few days. I don't seem to have a handy in-between size project that I can test stuff in. The closest I came to this was writing a little ad-blocking proxy for my browser, a few years back. Any ideas on neat small non-trivial projects?"

49 of 122 comments (clear)

  1. Pfff lots of things by arcanumas · · Score: 4, Funny

    There are lots of things you can write in two hours man!!
    voice recognition software, compilers, parser generators , browsers , OS kernels etc etc.
    Come on, be creative... :)

    --
    Slashdot Sig. version 0.1alpha. Use at your own risk.
    1. Re:Pfff lots of things by lostchicken · · Score: 3, Interesting

      I know you were kidding, but a parser generator really can be written in a couple of hours with a logical programming language like Prolog.

      --
      -twb
    2. Re:Pfff lots of things by bhtooefr · · Score: 2, Insightful

      What language? I can get you a web browser using MSHTML.DLL or Gecko in five minutes in VB (implementation is the same, as someone made mods to Gecko so that it worked as an ActiveX control, and IDENTICALLY to MS's HTML control).

    3. Re:Pfff lots of things by flonker · · Score: 2, Interesting

      Which brings up the point, can IE be changed to use Gecko as the rendering engine?

    4. Re:Pfff lots of things by bhtooefr · · Score: 2, Interesting

      Also, I don't think you want to change IE, because Windows Update doesn't work with Gecko.

      However, I think I DID find a way to get Gecko working in IE. Make it a Gecko plugin that associates itself with everything that IE does itself, without handing off to a plugin. I don't know if that will actually WORK, but it's worth a shot.

  2. a little easy but... by coolhoot2447 · · Score: 4, Interesting

    I usually start of with implementing some simple math related things. For example, a prime number generator or a program to calculate pi. The algorithms that you can use to write such a program tend to be heavily documented so you don't have to worry about the design and can concentrate on the implementation in that specific language.

    1. Re:a little easy but... by ddewey · · Score: 2, Interesting

      Or how about graphing fractals? My personal favorite is the Mandelbrot Set.

    2. Re:a little easy but... by saden1 · · Score: 4, Informative

      you can always got to Topcoder and check out some the problems they have over there. They have all sorts of coding problems with varying difficulties.

      --

      -----
      One is born into aristocracy, but mediocrity can only be achieved through hard work.
    3. Re:a little easy but... by cperciva · · Score: 2, Interesting

      ...or a program to calculate pi.

      Funny you should mention that. The first code I ever wrote in C was PiHex (a distributed project computing project, back in the days before those became cool, which computed the 5 trillionth, 40 trillionth, and quadrillionth bits of Pi. All of them were zero.)

    4. Re:a little easy but... by zuzulo · · Score: 2, Informative

      Some of the older languages have what they used to call 'finger exercises' or 'idiom lists' which are basically a long lists of small algorithms you can implement to get a very deep feel for a new language. I know idiom lists exist for APL, k, perl, and similar things likely exist for whichever language you are interested in learning.

      It might be helpful if you were to mention which particular language you were currently trying to master, however. ;-)

      --
      "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
    5. Re:a little easy but... by gnu-user · · Score: 2, Interesting

      Do you have pointers such lists?

  3. school/college programs by selfsealingstembolt · · Score: 5, Insightful

    Try to get your hands on some programming exams. The programs there are usually designed and written within one or two hours (to fit into a typical lesson). Also they touch all subjects that are of interest in your case, for example the 8-queen-problem for recursion, simple algebra (prime numbers) for number handling, pointers, etc without going to deep into details not necessary if you are not writing productive software.

    --
    Keep open minded - but not that open your brain falls out...
  4. open ended by MikeRepass · · Score: 2, Informative

    My suggestion is not to focus on a particular problem -> solution, but to think more open-ended. In essence, think of some general functionality that can be continually extended. Maybe an example will help clarify :)

    When I taught myself python, I first wrote a program that determined the word-wrap properties of a text file. It detected wrapping behavior across lines, and then constructed a range of possible wrap settings. I then added tabwidth detection. After this, I began to think about interpreting text structure from a document. So, if a block of lines exhibit wrap behavior, they're a paragraph, otherwise perhaps a section of code or a title. Then, I wrote a parser that accepted call backs, so, for example, it could (very roughly) convert etexts into html. Of course, this all took place over a week or so, and my knowledge of python evolved accordingly.

    So, my suggestion is don't think "final product," but rather work on a general library of functionality that you can extend as you go.

  5. Rock Paper Scissors by xanderwilson · · Score: 3, Insightful

    Or War (the card game), or a slightly more complex turn-based card game.

    Or, if you're terrible at programming or the programming language or compiler sucks, "Hello World!" might take a few hours.

    Alex.

    1. Re:Rock Paper Scissors by BlueCodeWarrior · · Score: 2, Insightful

      Games are good. I usually code up a short (9 or 10 room) text adventure...nothing overly complicated, but something that usually can use objects, pointers, functions, i/o...test out a bunch of different features.

  6. RPN Calculator by readams · · Score: 5, Insightful

    A friend of mine suggested a reverse-polish notation caclulator. It's a pretty good project since you'll have a chance to use a common data structure (stack) along with all the basic features of the language.

  7. What I do... by NetNifty · · Score: 5, Interesting

    What I do first of all after the basic "hello world" examples and stuff when learning a new language is a simple "guess the number" game - computer randomly generates number between 1 and 100.

    User then guesses, and computer replies if the guess is higher or lower until number is guessed. Teaches use of loops, random number generation, text input & output etc. Can also go on to store lowest number of guesses in "high score" table etc, or use TCP to make it playable over telnet, if you so wish.

  8. My issue by robotoil · · Score: 2, Funny

    My issue is not that I can't think of anything to write, but that I have writers block.

  9. Couple I've done by jbester1 · · Score: 5, Interesting

    Something simple like a basic Webserver (GET/PUT/HEAD) or a FTP server.

    You get:

    a) simple string parsing/processing/manipulation
    b) File I/O and filesystem manipulation
    c) Network I/O

    Optionally or language dependent:

    d) Threading
    e) Packaging

    If a dynamic language (e.g. lisp):

    f) Write something like JSP on top of it: dynamic dispatch to handling method/function

    Optimizations are easy as well. Caching will give you a good overview of data structure speed.

    1. Re:Couple I've done by Anonymous Coward · · Score: 2, Funny

      Lisp is a multiparadigm language, not a pure functional one. Mature web servers written in lisp have existed for years, and are typically not written in a functional style. AllegroServe and Araneida are probably the big two (they have different focuses, think apache vs. zope). http://www.cliki.net/Web

  10. how about... by Anonymous Coward · · Score: 5, Funny

    A random idea generator?

  11. Benefit the world: A program to show data splits. by Futurepower(R) · · Score: 4, Interesting


    Here's a simple program that would benefit the whole world:

    Make a program that shows what parts of a huge folder fit on individual CDs or DVDs. The output of the program would say, for example, that all the files from sub-folders A to Information would fit on the first CD, and all the files from sub-folders Installers to Netgear would fit on the second CD, and so on.

    It is necessary to store backup sub-folders in alphabetical order on the backup CDs or DVDs because then they can be found easily.

    Right now there is no good way to decide how to apportion the data. Breaking any file into two pieces just causes problems later, so the Easy CD Creator method does not work well.

    Later, it would be excellent if the program made .ISO files, of course, and even more excellent if the program asked the user to insert a CD or DVD, and burned the media.

    --
    100 Facts and 1 Opinion -- The Non-Arguable Case Against the Bush Administration

  12. Short coding project? by Andreas(R) · · Score: 3, Funny

    How about solving NP-problems in polynomial time? That should keep you busy for a few hours.

    1. Re:Short coding project? by damiam · · Score: 3, Informative

      Some NP problems are solvable in polynomial time. NP-complete problems, which the parent was probably referring to, are currently not.

      --
      It's hard to be religious when certain people are never incinerated by bolts of lightning.
    2. Re:Short coding project? by Anonymous Coward · · Score: 2, Funny

      Or coding an algorithm for generating Slashdot humor. Actually, that might be trivial.

      1. If the question is for something that is easy, suggest something that is hard.
      2. ???
      3. Laugh!

      Yeah, real funny. Sheesh.

    3. Re:Short coding project? by Spy+Hunter · · Score: 2, Informative
      No, you're confused and still thinking of NP-complete problems. NP problems and NP-complete problems are quite different.

      NP: problems whose solutions can be VERIFIED to be correct in polynomial time (as opposed to exponential time or some even faster-growing function of time). NP includes all trivial problems which can be solved in constant or linear time, since constants and linear functions are low-order polynomials. No non-deterministic turing machine is required to solve those.

      P: problems whose solutions can be FOUND in polynomial time. P is a subset of NP, and also includes all trivial constant- and linear-time problems.

      NP-complete: problems in NP which are reducible in polynomial time to any other problem in NP. This means that if you find a polynomial time solution to one NP-complete problem, you can solve any other problem in NP by the following process: translate the hard problem to the solvable one (in polynomial time), solve it (in polynomial time), and translate the answer back to the hard problem (in polynomial time), resulting in 3*polynomial time to solve the hard problem, which is still polynomial time. All those trivial problems in P and NP aren't included in NP-complete, since you can't reduce every hard problem in NP to those trivial problems (or at least, nobody has proven that you can; nobody's proven that you can't either, which is the whole problem).

      --
      main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
  13. IRC bot by Tobias+Luetke · · Score: 4, Insightful

    I implement a simple irc bot in whatever language i test. Usually takes few hours and you can write it as top down script or as oop monster, up to you.

    The good thing is that you can use this irc bot to test just about every aspect of the language later on. Its not a project which is just done and discarded. Possible enhancements are user recognition or even something fancy like cvs commit reporting.

    For example when i decided to play with sqlite took the ruby version of the bot and added a funny quotes database.

  14. Gravity by Mawbid · · Score: 3, Interesting

    I've written variations of this in a few languages. This small example exercises classes and operator overloading, collections and iteration, math, graphics, modularization, so it gives a pretty comprehensive view of what the programming system is like in real use. But the real reason I like it is because the output is mesmerizing.

    --
    Fuck the system? Nah, you might catch something.
  15. Programming challenges by ReKleSS · · Score: 4, Interesting

    My preference is the OSIX GEEK challenges, but anything with decent complexity will do fine. Solve the challenge first in a language you know, then reimplement in the new language. Just note that the first few geek challenges don't require much/any programming skill, and the first one could take a while. Take a look at Hackergames for more sites with the same type of challenges.
    -ReK

    --
    md5sum -c reality.md5
    reality: FAILED
    md5sum: WARNING: 1 of 1 computed checksum did NOT match
    1. Re:Programming challenges by gauchopuro · · Score: 2, Informative

      How about the ICFP contests, which have been featured on Slashdot many times? Entries are usually made for just about every language out there, so there is a good chance that someone else may have already used your language to implement a solution. After working out your own solution, looking at others' solutions could teach you even more about the language.

  16. Depends on your programming language by Nice2Cats · · Score: 3, Informative
    I think you need to be a bit more specific about which programming language you are talking about. In Python, a program that lets you write an email with your favorite editor and send it via SMTP is something you can do a few hours; however, in assembler, some of the most easy problems quickly get tricky:

    .file "helloworld.c"
    .section .rodata.str1.1,"aMS",@progbits,1
    .LC0:
    .string "Hello World"
    .text
    .p2align 4,,15
    .globl main
    .type main, @function
    main:
    pushl %ebp
    movl %esp, %ebp
    subl $8, %esp
    andl $-16, %esp
    movl $.LC0, (%esp)
    call puts
    leave
    ret
    .size main, .-main
    .section .note.GNU-stack,"",@progbits
    .ident "GCC: (GNU) 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)"

    Now try doing that without looking up things in a book -- obviously I cheated here and just used the GCC. You see what I mean, though: Writing a mail program in assembler is somewhat more tricky than Python.

  17. Pr0n to the rescue! by Bob+Cat+-+NYMPHS · · Score: 3, Funny

    Write a porn collector that will crawl through unlinked collections on free porn sites. I'll bet you've done this by hand already (no pun intended). It will have to figure out the directories and filenames from evidence in the linked parts. You'll be using simple AI and network stuff, but if you also want to look only for redheads, you'll be doing some graphics work too.

    If you use my idea, you should send me some redhead pix. Thank you.

  18. These are pretty easy by dtfinch · · Score: 3, Interesting

    You can try to reproduce some classic arcade games. Many of them are very easy to code in an afternoon.

    Here's an asteroids clone I wrote in javascript. It renders everything with divs.

  19. Two things by Sludge · · Score: 2, Interesting
    First, I write a CLI calculator. This gets me understanding simple I/O and type conversions.

    If the language has compelling semantic separation (usually object orientation), I'll write some form of random song guitar tab generator. That's a personal project of interest to me.

    Then I go back to Python.

  20. Re: BTTB by Tolomak · · Score: 2, Interesting

    For its own benefit, the world should give Burn to the Brim a try!

  21. I pretty much ... by schmu_20mol · · Score: 2, Interesting
    ...consider the approach Alex Stepanov describes in http://www.stlport.org/resources/StepanovUSA.html one of my favourites...
    ...And if they cannot implement max or swap or linear search, what chances do they have to implement really complex stuff? These are my litmus tests: if a language allows me to implement max and swap and linear search generically - then it has some potential.
    --
    "Nae Kin! Nae Quin! Nae laird! Nae master! We willna be fooled again!"
  22. Calculator - 4 functions to start, then trig funcs by astrojetsonjr · · Score: 4, Interesting
    I teach advanced programming at a local university. I often get students that want to get into the class without having the prior classes. I tell them to set aside 90 mins and to call/email me when they are ready to start.

    For the first hour (or whatever) it takes I have them write a four function calculator (FFC). Once they get that done, I have them extend it to add trig functions like sin / cos in the last 30 mins. If they can't do that, they are not going to be happy with harder assignments.

    I also use this as a mini-test of a new language. Try my new language COAL, better than Cobol, faster than VB, a true OO language with VM's that run on any Timex watch!! A short stint creating a FFC lets me know how well it works out.

    The FFC is also good since you can use it for GUI checkout to see if that new tool rocks as much as Freshmeat would like you to think.

  23. Go big by HeyLaughingBoy · · Score: 2, Insightful

    I'll skirt around your question and instead suggest after you get done with helloworld.lang you go straight to something interesting even if it's huge.

    Why? Well most 1 day projects aren't very challenging or interesting. But most major projects will have subsystems that you can do in one day, and the project in its entirety can hold your attention long enough that you may eventually complete it, by which time you're an expert in the language.

    This is pretty much the approach I had to take to learn C++ and OOP. I started a job knowing only C and the basic ideas of objects, and took on small bits of the C++ project until I could handle larger chunks.

  24. Hello World? by l0rd · · Score: 2, Insightful

    Hhmmmm....You'd figure somebody would have made this lame remark already.

    But seriously, a good project for learning a language depends on the language itself and the problems you yourself face. You're not gonna write a simple 3d engine in python and you're not gonna write a log parser in C (actually you could, but that wouldn't be the easiest/quickest solution).

    Just pick something trivial that bugs you at any given moment that's the right job for the language.

  25. Format converters by retrosteve · · Score: 3, Interesting

    A serious suggestion --

    Look at your favorite text, sound, or graphic format that you've had trouble converting to or from some other format. Write the converter.

    This can range from 1 hour to a week's work, but it's always instructive and usually fun.

  26. Graph algorithms by cakoose · · Score: 2, Informative

    Graph algorithms are good for testing out a language's data structures. Dijkstra's single-source shortest path function is a good one to start with.

  27. I've got a good one... by crazyphilman · · Score: 3, Interesting

    Do "Towers of Hanoi".

    You've got three posts, and up to 64 disks, with the largest disk slid down to the bottom of the first post and the smallest disk at the top, and the diameters of the disks tapering.

    You have to move all the disks from the first post to the third post in such a way that no disk is ever placed on a smaller disk, and only one disk is moved at a time, one post at a time. It's harder than it looks.

    Your goal: model the three posts and the 64 disks. Write a program that moves the disks from the first post to the third via the middle one, without ever violating the rules. Record the sequence, and let it run, finding the shortest sequence that works.

    It's kind of a fun one.

    --
    Farewell! It's been a fine buncha years!
  28. Make a chess game... by Ramses0 · · Score: 3, Interesting

    I like writing a chess game... there are sufficient enough ways to implement a two-player (human) game, and enough corner cases that it's an interesting problem with well-defined rules. Have fun!

    --Robert

  29. Code for others! by sachachua · · Score: 4, Insightful

    When I'm studying a language, I like finding an open source project I care about and looking for something to tweak. Advantages of this include feedback from other developers, an instant framework to fit your small changes into, and the warm and fuzzy feeling you get when you make something other people will use. You can pick up the idioms of the language quickly by reading code used in real life. Participating in an open source project also connects to a lot of other people who already know the language you want to learn, and you can ask them for help.

    Don't be intimidated by the size of projects. Pick a project, browse through the source code, try to get the feel of things. You can usually find a bug report small enough for you to work on. If not, think of a feature you'd like to have and try to implement it. =)

    Great way to get into a language.

  30. Useful first exercise - cubic equation solver by viking_kiwi · · Score: 2, Interesting

    I do numerical modelling for process engineering and my first programming exercise with a new language is to write a cubic equation solver based on that in the Numerical Recipies books. This exercises all of the basics, particularly math funtions (square roots, powers and trigenometry) as well as basic conditionals. The resulting code is actually useful in my work - I now have versions in Fortran (the original NR Fortran book didnt actually supply code), C, C++, Java, Tcl, and Python!

    On a related note the very first significant program I ever wrote was as an exercise in Fortran programming on punched cards - a quadratic equation solver. Most of the same elements were there - mathematical functions and conditionals, with the additional complication of requiring formatted output - you had to decide if the roots were real or imaginary and print them in a suitably formatted way, so the exercise also taught you how to do output of strings. I seem to remember it took about three days to complete the exercise, but in those days of submitting batches of punched cards the compile - run - debug cycle was 24 hours!

  31. Tetris by marcovje · · Score: 4, Informative


    I usually write a tetris clone.

    Basic operation is 400-1000 lines typically

  32. Re:Tic Tac Toe... by OneDeeTenTee · · Score: 2, Funny

    Cool.

    I did a self learning tic-tac-toe game once, using Martin Gardner's matchbox learning algorithm.

    It learned so well that it started to cheat.

    --
    Stop the world; I need to get off.
  33. 21 short exercises by Dave (Pragmatic) Thomas by mahlen · · Score: 2, Informative

    http://pragprog.com/pragdave/Practices/Kata

    For the lazy or doubtful, here's the list of descriptions:

    KataOne: Supermarket pricing. Pricing looks easy, but scratch the surface and there are some interesting issues to consider.
    KataTwo: Karate Chop. A binary chop algorithm is fairly boring. Until you have to implement it using five totally different techniques.
    KataThree: How Big, How Fast? Quick estimation is invaluable when it comes to making design and implementation decisions. Here are some questions to make you turn over the envelope.
    KataFour: Data Munging. Implement two simple data extraction routines, and see how much they have in common.
    KataFive: Bloom Filters. Implement a simple hash-based lookup mechanism and explore its characteristics.
    KataSix: Anagrams. Find all the anagram combinations in a dictionary.
    KataSeven: Reviewing. What does our code look like through critical eyes, and how can we make our eyes more critical?
    KataEight: Objectives. What effects do our objectives have on the way we write code?
    KataNine: Checkout. Back to the supermarket. This week, well implement the code for a checkout system that handles pricing schemes such as "apples cost 50 cents, three apples cost $1.30."
    KataTen: Hash vs. Class. Is it always correct to use (for example) classes and objects to structure complex business objects, or couple simpler structures (hash as Hashes) do the job?
    KataEleven: Sorting it Out. Just because we need to sort something doesnt necessarily mean we need to use a conventional sorting algorithm.
    KataTwelve: Best Sellers. Consider the implementation of a top-ten best sellers list for a high volume web store.
    KataThirteen: Counting Lines. Counting lines of code in Java source is not quite as simple as it seems.
    KataFourteen: Trigrams. Generating text using trigram analysis lets us experiment with different heuristics.
    KataFifteen: Playing with bits. A diversion to discover the pattern in some bit sequences.
    KataSixteen: Business Rules. How can you tame a wild (and changing) set of business rules?
    KataSeventeen: More Business Rules. The rules that specify the overall processing of an order can be complex too, particularly as they often involve waiting around for things to happen.
    KataEighteen: Dependencies. Lets write some code that calculates how dependencies propagate between things such as classes in a program.
    KataNineteen: Word chains. Write a program that solves word chain puzzles (cat -> cot -> dot -> dog).
    KataTwenty: Klondike. Experiment with various heuristics for playing the game Klondike.
    KataTwentyOne: Simple Lists. Play with different implementations of a simple list.

    mahlen

  34. A single-file database server and client by rjshields · · Score: 2, Interesting

    Use a simple data file format and allow for CRUD operations. Write a network server and GUI clients. Covers file IO, collections/data structures, networking and GUI. Bit boring, mind :)

    --
    In this world nothing is certain but death, taxes and flawed car analogies.