• Solo (unregistered) in reply to Jelmer
    Anonymous:

    Anonymous:
    At least hire someone who knows how to copy code off of the Internet. I know that gets a bad rap, but a significant portion is better than this sort of thing.

    But what if they copy from this site? 

    Everybody knows the source of good code snippet is on codeproject. It's the ultimate repository of high quality code that promotes code reuse.

    Captch: awesomeness, indeed! 

  • Miral (unregistered) in reply to Solo
    Anonymous:

    Everybody knows the source of good code snippet is on codeproject. It's the ultimate repository of high quality code that promotes code reuse.

    Where by code reuse you mean extreme copy & paste, of course :-).
  • Anonymous (unregistered) in reply to Miral

    Sorry for the VB6 snippet; I'm a bit bored and I felt like killing 5 minutes. This is a slightly more efficient way of reading a file line by line.

    Public Sub ReadFile(ByVal fileName As String)
    Dim fileContent As String
    Dim fileLines() As String
    Dim fileHandle As Long
    Dim lC As Long

        fileHandle = FreeFile
        Open fileName For Binary Access Read Shared As #fileHandle
        fileContent = Space(LOF(fileHandle))
        Get #fileHandle, 1, fileContent
        Close #fileHandle
        fileLines() = Split(fileContent, vbNewLine)

        '//Look, mom! Line by line.
        For lC = LBound(fileLines) To UBound(fileLines)
            Debug.Print fileLines(lC)
        Next

    End Sub

    Captcha: creative :-) 

  • sergiogiogio (unregistered) in reply to Anonymous

    Not a WTF to me. Yeah, deleting first line in the loop is slow, but if the loop crashes (or is made to stop) on a specific (input) line, the program will resume processing starting exactly from that (input) line again on next startup, which might be an important requirement of the program.

    Now try to think of how you would have done it otherwise? Counters? Databases?... Each has its own problems, at least the solution adopted by the code snippet is simple and works.

     

  • (cs) in reply to sergiogiogio

    Internet Troll:

    Trolls can be found under network bridges, and actually post factual information, and are kind and considerate to other posters on Internet forums. They try very hard to give people a good experience.

    sergiogiogio:
    Not a WTF to me.


    Dear sergiogiogio,
           WTF IS WRONG WITH YOU
    DaBookshah

  • Michael Lush (unregistered)

    If were swapping file opening tips here is a perl one

    foreach (<FILE>) { print; }

    while(<FILE>) {print;}

     Both do the same thing. The difference comes when you point foreach at a your server logs and it runs out of memory!  Foreach reads every line in the file into an array then steps through it, while reads it one line at a time.
     

  • Eternal Density (unregistered) in reply to Incen
    Anonymous:
    Arancaytar:
    From now on, I will read books by opening them, reading a page, ripping it out, closing the book and opening it again.

    Or wait, somewhere in between I'm going to copy the book from beginning to end each time. It looks like the program does that at some point, but I couldn't figure out when or why.

     

    It makes perfect sense, really, if you're reading in the wind or otherwise difficulties with turning pages. And ripping out pages can really screw with a book's structural strength, so you obviously need to rewrite the entire book (bar the read page) after damaging it. The wind won't be a problem here if you have someone else reading the book out loud to you, and because everyone knows that you lie down ontop of the paper when you write something, thus weighing it down.

    And then you have the other guy copy the book you produced, because you have horrible handwriting and wouldn't be able to read it yourself. And then you can throw away the other 2 books, because they're pretty useless, and proceed to the next page. Really, it's the only way.

     

    CAPTCHA: mustache. Now that I think about it, this did make me feel a little sleazy.

    You rip out the first page and read it.  Then you but the book on a wooden table and photograph each page with a digital camera.  Then print them out and rebind them.  Then burn the original book.  Rinse, repeat.

    captcha = hacker (me != hacker) 

  • (cs) in reply to sergiogiogio
    Anonymous:

    Not a WTF to me. Yeah, deleting first line in the loop is slow, but if the loop crashes (or is made to stop) on a specific (input) line, the program will resume processing starting exactly from that (input) line again on next startup, which might be an important requirement of the program.

    Now try to think of how you would have done it otherwise? Counters? Databases?... Each has its own problems, at least the solution adopted by the code snippet is simple and works.

     


    Um. A process stops for an unknown reason. Lets assume power goes off. Lets say it has processed the line. But has not as yet deleted it. Time for power to go off.

    Power comes on. Script reads first line (already processed).

    Do you see the problem?

    In a database the queries to store the result and to cleanup the input row can be made atomic.
  • (cs) in reply to VGR

    The version of Hungarian that sucks is the VB version.

     For some reason, the VB team didn't "get" the real reason to use Hungarian, which is not to tell everyone what datatype a variable is - it's to inform people about the USE of that datatype. This, even at a time when the damn IDE was quite capable of telling you what datatype a given variable was.

    http://www.joelonsoftware.com/articles/Wrong.html

    So it's more about saying to the coder things like "this variable contains nasty unsafe user input", or "this variable is being used to carry coordinate data" or "this is the length of a byte buffer". Preventing you from doing things like assigning the buffer length to a variable containing an X-coord. Which is perfectly legal if they are both the same datatype.

    intWindowTopLeftX = intLength

    xWindowLeft = cbLength

    VB style hungarian at the top looks far more plausible as good code than the latter line which is proper "Simyonian" hungarian in its original sense.
     

    Of course, these days, you'd be less inclined to use it because OO means that the context that most simple datatypes appear in is structs and objects, and well designed systems abstract things away to the point where if you try and assign a buffer length to a Point, the compiler will squeal.

     

  • Blah (unregistered) in reply to Maurits
    Maurits:

    Anonymous:
    Then the stupid thing reset, and instead of doing the non-completely retarded thing and giving me my card back, it vomited me a fucking ticket stating that my card was kept (and probably to go fuck myself and contact my bank).

    Think about this for just a minute and perhaps you'll see why they do it this way.

    A more sensible option would be to prompt the person for their PIN again. If the owner has walked off after kicking a small dog in disgust, no harm no foul. If the owner is still there, they can retrieve their card.

    And don't tell me that this suggestion is insecure. It can only be insecure if the entire banking system relies on a 4 digit security code that... oh, wait a sec. Yep, retarded.
     

  • (cs) in reply to Nachoo
    Nachoo:

    The moral of the story is: Intensify controlling principles.

     
    Why let an expensive human code something that an underpaid gorilla could do as well?
     

    <font size="+1">P</font>rices have gone up since gorillas are a protected species and there is now a shortage of them.  Bananas have also skyrocketed in cost.
  • rp (unregistered) in reply to benw-24

    Yuck, I hate that: hardcoded filenames.

    Just write

    #! /usr/bin/perl
    while (<>) {
    /* do stuff */
    }

    and supply the filename(s), if any, on the command line.

  • wade b (unregistered) in reply to Anonymous

    You should not rely on Split like that in a production process.

    The first time you get a truncated file watch what happens...

    Reading the file a line at a time and processing that line is often a better approach, allowing the program to evaluate each line as it exists, and fail gracefully on a malformed line if it is found.

  • Sgt. Preston (unregistered) in reply to Zlodo

    [quote user="Zlodo"][quote user="Tim Gallagher"]...Somewhat related to the subject, I had the displeasure of having an ATM crash on me yesterday. With my credit card inside...[/quote] We're getting off topic, but I wanted you to know, Zlodo, that this doesn't just happen in Norway. In 1991, I was in Montreal, Canada, on a business trip and dead tired from too many long days. I put my bank card into an ATM to get some cash. It politely told me that it was not on Interac (which is the principal inter-bank ATM system in Canada) and then impolitely kept my card. So there I was, 700 km from home, with no cash, no bank card, and several days of work to do yet. And of course it was a Sunday, so the bank was closed.

    I drew a cash advance on my company credit card to get by. My company was not pleased, of course. On Monday, I went to the bank and was told that they could not return the card to me. The card would be mailed to my home bank "for security reasons."

    When I got home several days later, my bank told me that they would watch for my card and notify me when they received it. When it arrived, naturally, they destroyed it and didn't tell me anything. Eventually, I had to get a new card issued.

  • marek (unregistered)

Leave a comment on “The Jewel of the File”

Log In or post as a guest

Replying to comment #:

« Return to Article