FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


What's the most complicated piece of code you've ever wrote





davidv
1. What does your programme do or rather, what did it end up doing?

2. What language did you use and why did you choose that particular language?

3. Why did you decide write it?

4. Have you finished it or are you still adding features?

5. What part of your programme are you most proud of?
badai
when you said "piece of code", it must be just few lines of code which is doing a very complicated routine and hard to write, right? not a whole bunch of application with millions of lines.

ok, the one that i can recall is last year.

1. it just a few lines of code, not a program. what it does: show the range of phone numbers when user enter the base range, first number, last number and number of lines (phone numbers) that it should have.

example:
input:
range: 2190
start: 200
end: 399
no. of lines: 200

output:
range[0] => 21902XX
range[1] => 21903XX

example 2:
input:
range: 2190
start: 1999
end: 2048
no. of lines: 50

output:
range[0] => 21901999
range[1] => 2190200X
range[2] => 2190201X
range[3] => 2190202X
range[4] => 2190203X
range[5] => 21902040
range[6] => 21902041
range[7] => 21902042
range[8] => 21902043
range[9] => 21902044
range[10] => 21902045
range[11] => 21902046
range[12] => 21902047
range[13] => 21902048

and of course it will check for error:
input:
range: 2190
start: 1999
end: 2048
no. of lines: 40

output: get a calculator!!

this is the real output, btw. there is another system where you get your start number and you enter number of lines required and it will give you the last number. so the only way you can input the wrong data is if you calculate it yourself.

2. javascript. it's a web base application, and use ajax to interact with back end. we use javascript because it's web base, and we use web base so that everybody can use it regardless of platform and OS version. if you can't use it, your browser sucks! get a chrome or pale moon. or just use IE. it will work.

3. it's part of the requirement. believe it or not, for as long as they can remember, they have to do it manually (maybe since 1940s), and no vendor before us can write code to do it. some did try but will get the wrong result. they were really impressed with us. btw, until today i still believe it may produce error because I can't really test it with all possible combination of input range, start and last number.

4. finished. finish it in few hours, then the next day discover error and fix it in 1 hour. they never complaint and it's been more than a year now. warranty and maintenance expired last month. so we are not adding features nor do any fix.

5. part of the program, of course this piece of code. why would there be another part if this happened to be the most complicated? this is really the most redundant part of your question.

and this is the piece of code, free to use and modify:

Code:
if ((parseInt(parseFloat(lev_c + end_lev_c)) - parseInt(parseFloat(lev_c + start_lev_c)) + 1) != no_of_lines) {
            alert("get a calculator!!");
            return false;
         }
         
         if ((end_lev - start_lev + 1) != no_of_lines) {
            alert("get a calculator!!");
            return false;
         }
         
         var out = "";
         var range = [];
         range[0] = parseInt(parseFloat(lev_c + start_lev_c));
         while (range.length < no_of_lines) {
            range[range.length] = range[range.length - 1] + 1;
         }
         
         var range_c = [];
         for (var l = 0; l < range.length; l++) {
            range_c[l] = range[l] + '';
         }
         
         var range_c_t = [];
         var assigned_line = 0;
         while (assigned_line < no_of_lines) {
            if (range_c[assigned_line].substring(range_c[assigned_line].length - 1) != "0") {
               range_c_t[range_c_t.length] = range_c[assigned_line];
               assigned_line++;
               continue;
            } else {
               if ((no_of_lines - assigned_line) >= 10) {
                  range_c_t[range_c_t.length] = range_c[assigned_line].substring(0, range_c[assigned_line].length - 1) + "X";
                  assigned_line += 10;
                  continue;
               } else {
                  range_c_t[range_c_t.length] = range_c[assigned_line];
                  assigned_line++;
                  continue;
               }
            }
         }
         range_c = range_c_t;
         
         var filter;
         for (var l = 0; l < range_c.length; l++) {
            filter = range_c[l].indexOf("X");
            if (filter != -1)
               break;
         }
         
         var X = "";
         for (var mm = 0; mm < range_c.length; mm++)
            out += "<br />" + range_c[mm];
         out += "<br />";*/
         for (var l = filter; l >= 0; l--) {
            X += "X";
            range_c_t = [];
            var loop = 0;
            while (loop < range_c.length) {
               if (range_c[loop].indexOf(X) == -1) {
                  range_c_t[range_c_t.length] = range_c[loop];
                  loop++;
                  continue;
               } else {
                  out += "<br />range_c[loop].substring(0, l - 1) = " + range_c[loop].substring(0, l - 1);
                  if (((loop + 9) < range_c.length))
                     var ****** = range_c[loop + 9].substring(0, l - 1);
                  else
                     var ****** = "******!! miss it!!";
                  out += "<br />range_c[loop + 9].substring(0, l - 1) = " + ******;
                  out += "<br />range_c[loop].substring(l, 1) = " + range_c[loop].substring(l, l + 1) + "<br />";*/
                  if (((loop + 9) < range_c.length) && (range_c[loop].substring(0, l - 1) == range_c[loop + 9].substring(0, l - 1))
                      && (range_c[loop].substring(l, l + 1) == "X") && (range_c[loop + 9].substring(l, l + 1) == "X")) {
                     range_c_t[range_c_t.length] = range_c[loop].substring(0, l - 1) + X + "X";
                     loop += 10;
                     continue;
                  } else {
                     range_c_t[range_c_t.length] = range_c[loop];
                     loop++;
                     continue;
                  }
               }
            }
            range_c = range_c_t;
         }
         
         for (var l = 0; l < range_c.length; l++)
            out += "<br />arr[" + l + "] => "+ range_c[l];
davidv
Quote:
when you said "piece of code", it must be just few lines of code which is doing a very complicated routine and hard to write, right? not a whole bunch of application with millions of lines.


The question said "programme" but the title said "piece of code". I both terms are interchangeable to me so whichever is fine.

Quote:
5. part of the program, of course this piece of code. why would there be another part if this happened to be the most complicated? this is really the most redundant part of your question.


The question asked which part of your programme are you most proud of.

Nonetheless, interesting script. Thanks for sharing Very Happy
badai
davidv wrote:
Quote:
when you said "piece of code", it must be just few lines of code which is doing a very complicated routine and hard to write, right? not a whole bunch of application with millions of lines.


The question said "programme" but the title said "piece of code". I both terms are interchangeable to me so whichever is fine.

Quote:
5. part of the program, of course this piece of code. why would there be another part if this happened to be the most complicated? this is really the most redundant part of your question.


The question asked which part of your programme are you most proud of.

Nonetheless, interesting script. Thanks for sharing Very Happy


1. nothing to do with program or piece of code actually, just to clarify should it be piece of code or the whole system.

2. this is really contradictory if we refer back to 1, if program is equal to piece of code (as you said interchangeable), than why ask again which part of the program? this make it look like the program is the whole system, and the whole 5 questions is regarding the whole system with the 5th question specifically ask which part of it. if you stick with 1, then it will become more complicated to find which part from the piece of code (which is equivalent to the program) is i'm proud of. hmmm... the for loop? the while loop? nah... maybe the alert statement. it's not always you can make the user look stupid.
davidv
This is really off-topic. You really like to stir up trouble... but okay. I haven't got anything to do right now so I'll feed the troll.

So let's reiterate the title, questions and the premise that code and programme is interchangeable, also let's define the term code.

Title:
Quote:
What's the most complicated piece of code you've ever wrote


Questions:

Quote:
1. What does your programme do or rather, what did it end up doing?

2. What language did you use and why did you choose that particular language?

3. Why did you decide write it?

4. Have you finished it or are you still adding features?

5. What part of your programme are you most proud of?


Definition:

Quote:
code
noun /kōd/ 
codes, plural

A system of words, letters, figures, or other symbols substituted for other words, letters, etc., esp. for the purposes of secrecy
- the Americans cracked their diplomatic code
- sending messages in code

Program instructions
- hundreds of lines of code
- assembly code


I'd like to quote "hundreds of lines of code" for you.

Quote:
nothing to do with program or piece of code actually, just to clarify should it be piece of code or the whole system.


I surely hope you're not suggesting that I can't pose questions that aren't defined by your presets.

Quote:
this is really contradictory if we refer back to 1, if program is equal to piece of code (as you said interchangeable), than why ask again which part of the program?


Question 1 asked what your program does. How does that contradict anything? I take it you're referring to the title. If you wish to interpret code as just a snippet rather than a system, you're still wrong. A snippet code although only a small portion of the entire system still can have multiple regions which may be considered complicated. Surely you have seen a single line of code that out weighs multiple functions. Example:

Code:
match = re.finditer('[a-zA-Z0-9\-_\.]+[^\.\.\.]@[a-z\.]+\.+[a-zA-Z\.]+', line)


I wrote this a while ago to match emails in a fairly large dataset. Is this not part of the code?

... and if you decide to interpret code as being interchangeable with an entire system then... I must say that complex programmes that we design aren't always linear. What I mean by this is that good programmers follow the divide and conquer paradigm which intertwines into many of the popular and evidently successful software engineering mythologies. Consequently due to such a nature, we section our programme into parts or rather classes and functions (for modularity sake).

When I asked which part of the programme/code you are most proud of, I was referring to classes, functions, a suggestive snippet of code implemented in your language of choice. I was not referring to syntax as you have blatantly stated.

Oh, yes. On a side note. Just because a piece of "code" is complicated, it doesn't mean you are proud instantly of it. It just implies it's complicated. I'd be much happier if I could solve a problem with code that's easy to read and understand than one that's convoluted and unmaintainable.

One more thing. There are redundancies in your code. You may want to fix it.

EDIT: One very very last thing I must add. If you found my questions silly, contradicting or redundant. There isn't anyone with a gun pointed at you, forcing you to post.
badai
chill out.

you're right and i'm totally a loser. sorry about that.
kta_fh
What I describe here was not complicated to implement. The point is that the programme was/is able to create very complicated processing.

1. What does your programme do or rather, what did it end up doing?
It shows a sequence of setting dialogs each governing a conversion/filter to an image. A conversion/filter may be iteratively built from other conversions/filters.

2. What language did you use and why did you choose that particular language?
Tcl/Tk.

3. Why did you decide write it?
It was part of a Print application for SunOS. I got paid doing it Smile

4. Have you finished it or are you still adding features?
I finished it back in 90's.

5. What part of your programme are you most proud of?
The drag-and-drop feature for adding conversion/filter steps to a target. It was all-in-all very easy to use. You just dragged these LEGO-like UI elements on top of each other and created new combinations. Every drop was evaluated for interoperability (output-input match).
Peterssidan
Quote:
1. What does your programme do or rather, what did it end up doing?

It is a Game Boy emulator so it emulates Game Boy games.

Quote:
2. What language did you use and why did you choose that particular language?

First plan was to use JavaScript but we decided to use Java because it would probably be faster and all of the team knew Java. We could still put it on a website as a Java Applet.

Quote:
3. Why did you decide write it?

It was a bachelor project. Someone had proposed it as a project and I thought it sounded very interesting. We were 6 persons in the project so I only wrote parts of of it.

Quote:
4. Have you finished it or are you still adding features?

It can run many games but there are still things to improve to support more games. We haven't worked on it since the project ended. A bit sad Sad

Quote:
5. What part of your programme are you most proud of?

I'm most proud of the part that emulates the CPU because I wrote most of it in very short time. Of course it contained some bugs that had interesting effects later on but it allowed us to get something going quickly. I'm also proud of the code added to support Game Boy Color games.
davidv
Quote:
It was a bachelor project. Someone had proposed it as a project and I thought it sounded very interesting. We were 6 persons in the project so I only wrote parts of of it.


What's it like to work in a team? I've always programmed alone and at most just discussed what I've done, how I've done it and how fast it was. How did you manage the code? How did you assign tasks? What happens when you had one single function that every part of your programme relied on? How did you sort these things out?
Peterssidan
davidv wrote:
What's it like to work in a team?

It was more fun and you learn more. You can't write sloppy code because you know people will complain if you do.

davidv wrote:
How did you manage the code?

We used a SVN repository to handle the files. We had a coding standard to follow and we used checkstyle to verify that the code followed the coding standard. We also had a few code review sessions to give constructive critics about the code.

davidv wrote:
How did you assign tasks?

We handed out tasks to groups of two and had a deadline when it should be finished (or almost finished because you often had to go back later to fix things when new things was added). Within the groups it was up to them how they distributed the work. There was still a lot of communication between the groups and we often met to discuss things that came up. After the deadline we handed out new tasks and possibly changed the groups. We used Trac to handle all bug reports and to assign it to the right people that was responsible for that part. Not all work was about writing code. There was much report work to be done too.

davidv wrote:
What happens when you had one single function that every part of your programme relied on?

You need to agree together on the interface to be used to communicate between different parts. The memory class needed read and write methods that could be used by the CPU class to read and write from memory. The CPU class needed a method to execute the next instruction etc. When the more basic functionality was implemented we could start implement graphics, sound and other things that relied more heavily on other parts to work.
Fire Boar
davidv wrote:
What happens when you had one single function that every part of your programme relied on?


Usually if this is the case, you're doing it wrong. Some utility code may be re-used in many places, but it should all be self contained, with a consistent interface. As Peterssidan mentioned, having a reliable interface is crucial for teamwork, and if you're going to change an interface, everyone in the group should know. Often in larger teams, removing a feature from the interface involves adding a "deprecated" tag to the method while still providing its functionality. The rest of the team should then rewrite anything using deprecated code when they can.

Working on code in a team is definitely something every programmer should do. Two people of a roughly similar expertise working together at the same time can get three times the amount of coding done as one person alone. But mostly "coding in a team" just means that you're not the sole driving force behind the project, that there are several programmers. This results in great productivity on the project, but you need communication and a good version control system. I like using Git, personally, since it offers very cheap, pain-free branching and merging, which lets you work on and commit experimental features without affecting the code base.
daikirai
davidv wrote:
1. What does your programme do or rather, what did it end up doing?

2. What language did you use and why did you choose that particular language?

3. Why did you decide write it?

4. Have you finished it or are you still adding features?

5. What part of your programme are you most proud of?


- Generate a random password using in-house algorythm. The passwords are then stored in MySQL database, hashed with an in-house hashing method.

- PHP. It's a part of the webpage project I did.

- Basically I'm forced to write it, or my paycheck would be cancelled Very Happy

- Finished. And I'm glad.

- That I completed the script, finally. It's giving me and my team headache, and it's the most vital part of the web project.
Related topics
Emulator - A Hardware Based Learning Model
What's the most difficult game you've ever played?
myspace code problems
Why do you all hate God?
C++ int to char and char to int
Custom Windows Program Shop (Simple Only)
Triple suicide at Guantanamo Bay
What was the most AMAZING thing you have ever done in life ?
Musical Taste Defines Personality?
What Religion are You?
My Blog: 10 reasons not to get married
Anyone happy with Typo3?
greatest hero ever!!!
Aferlife?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.