Any WTF's?



  • I'm in a high school Computer Science class. We are currently working on Java console applications.

     Our final assignment was to write a program that has three options:

        Store Information
        Search and Read Information
        Quit Program

    I finished early as usual. It works but i want to know if i have any WTF's in my code.

    import java.io.;

    public class FinalCS {
       
        public static void main (String[] args) throws IOException
        {
            String Query = "";
            InputStreamReader converter = new InputStreamReader(System.in);
            BufferedReader in = new BufferedReader(converter);
            QueryLoop:
            while(!(Query.equals("QUIT")))
            {
                System.out.println("\nCHOOSE FROM THESE OPTIONS:\n| ENTER | SEARCH | QUIT |");
                Query = in.readLine().toUpperCase();
                if(Query.equals("ENTER"))
                {
                    EnterStuff();
                    continue QueryLoop;
                }
                else if(Query.equals("SEARCH"))
                {
                    SearchStuff();
                    continue QueryLoop;
                }
                else if(Query.equals("QUIT"))
                {
                   
                }
                else
                {
                    System.out.println("INVALID SELECTION.\n");
                }
            }
            System.out.println("END OF LINE.");
        }
        public static void EnterStuff()throws IOException
        {
            InputStreamReader converter = new InputStreamReader(System.in);
            BufferedReader in = new BufferedReader(converter);
            System.out.println("ENTER NAME(LAST, FIRST):");
            String Name = in.readLine();
            System.out.println("ENTER ADDRESS:");
            String Address = in.readLine();
            System.out.println("ENTER JOB:");
            String Job = in.readLine();
            System.out.println("ENTER MATERIAL COST:");
            double MatCost = Double.parseDouble(in.readLine());
            System.out.println("ENTER LABOR COST:");
            double LabCost = Double.parseDouble(in.readLine());
            double TotalCost = (MatCost
    1.0825)+LabCost;
            try
            {
                FileOutputStream fout;
                fout = new FileOutputStream (Name + ".txt");
                new PrintStream(fout).println ("NAME: "+ Name + ";" + "ADDRESS: " + Address + ";" + "JOB: " + Job + ";" + "MATERIAL COST:" + MatCost + ";" + "LABOR COST: " + LabCost + ";" + "TOTAL COST: " + TotalCost);
                fout.close();
                System.out.println("\nINFORMATION STORED.\n");
            }
            catch(IOException e)
            {
                System.out.println("\nCOULD NOT STORE INFORMATION.\n");
            }
           
        }
       
        public static void SearchStuff()throws IOException
        {
            InputStreamReader converter = new InputStreamReader(System.in);
            BufferedReader in = new BufferedReader(converter);
            System.out.println("\nENTER NAME OF CLIENT. (LAST, FIRST)");
            String Name = in.readLine();
            try
            {
                FileInputStream fin;
                fin = new FileInputStream (Name + ".txt");
                String Info = new DataInputStream(fin).readLine();
                int count = 0;
                char separator = ';';
                int index=0;
                do                                            
                {
                    ++count;                               
                    ++index;                               
                    index=Info.indexOf(separator, index);
                }   
                while (index!=-1);
                String[] subStr=new String[count];           
                index=0;                                   
                int endIndex = 0;                           
                for (int i=0; i<count; i++)                   
                {
                    endIndex=Info.indexOf(separator, index);
                    if (endIndex==-1)
                        subStr[i]=Info.substring(index);
                    else
                        subStr[i]=Info.substring(index,endIndex);
                   
                    index=endIndex+1;
                }
                for (int i=0; i<subStr.length; i++)
                    System.out.print(subStr[i] + "\n");
                fin.close();
            }
            catch(IOException e)
            {
                System.out.println("\nCOULD NOT LOCATE CLIENT.\n");
            }
        }

    }

     

    Strong critiques are very much accepted. I want to major in CS so all help is appreciated. 



    • Java naming conventions do methodNamesLikeThis, not MethodNamesLikeThis.  Following those conventions will make it easier for other programmers to read your code in the future, so it's a good habit even for code you expect to throw away at the end of the course.  Same for variableNames.
    • Named continue statements, or even any continue statements, are unnecessary in your main loop.  Not a WTF, as such, just unnecessary code.
    • Your main method isn't too bad, though I'd consider replacing the if/elseif/elseif block with named command objects if you end up adding more commands.
    • The EnterStuff method and SearchStuff method should be broken up into other, smaller methods.
    • Instead of reloading the data every time you need to search, consider loading it on startup and saving it when you quit.
    • The do/while loop in SearchStuff might be replacable with the split method on String.



  • Avoid import statements which use an asterisk ("*").  Explicit import statements are better because they explicitly list a class's external dependencies.



  • I know almost nothing about Java, but I suggest you avoid using any of the following "meaningless" words in database/table/field/program/function names:

    Stuff, Thing, Data, Number, Value, Go, Do, Perform, Execute, It and so forth.

    Method "SearchStuff()" could be just "Search", unless that's a reserved word of course, in which case think of something better and more descriptive. I once saw a table called "DataValues", which caused me to froth at the mouth - what table doesn't contain data or values?!



  • Thanks.

     These comments are very helpful. I am glad there is a forum where people are able to critique work without being rude.

     

    Anything else is appreciated.



  • No WTFs as such, but a few things that mark you out as a newbie (which you are, so it's not too much of a problem).

    • continue label should, imo, only be used where necessary. When I read that I did go 'wtf?' because I didn't know where it was continuing to, assuming it wasn't the immediately encolsing loop (which it is).
    • IMHO it would be neater to have your main loop be
      while(true){
       ...
       if("QUIT".equals(Query)) break;
      }
      That makes it more explicit that the 'quit' command breaks out of the loop. And it saves an extra test every time through the loop, unless the compiler ditches the current empty if.
    • Capitalisation is not following the standard Java conventions – minor point but good to know if you want to write Java for real. Your code looks more C#, though variable names are camelCase in that too.
    • Commands should be accepted in either case, or at least in lower case. I think there's an equalsIgnoreCase so you can just use that
    • It would be good if you could type the data for a whole job in one go, however I recognise that's not trivial with an address in there.
    • Again as mentioned already, a lot of Search can be done with the methods on the String class (String.Split, String.IndexOf(String)).

     And of course The Real WTF (TM) is that you're using Java ;)



  • Commands should be accepted in either case, or at least in lower case. I think there's an equalsIgnoreCase so you can just use that

     If you look closely, the commands are accepted in both cases. They are then converted to uppercase when testing the commands. entering "enter" would give the same result as "ENTER" and "EnTeR."

     

     And of course The Real WTF (TM) is that you're using Java ;)

    I know. :) In the beggining of the course my teacher decided Java was the way to go. I really didn't support his decision.

     

     



  • So, without seeing the actual assignment that you are supposed to solve, here are my initial reactions to what you have written.

    •  Like everyone else, I immediately reacted to your use of the label/continue statement.  It's unnecessary, and confusing, especially when it goes to the top of the enclosing loop.  With your current if/else logic, you don't even need a 'continue', just let it fall through and reloop.
    • Double.ParseDouble() will throw a NumberFormatException if it receives improperly formatted data.  You do not catch this exception anywhere in your code, so the unchecked exception will cause your program to exit.  It is generally considered bad form for a program to exit based on poorly formatted data.
    • Input integrity checking, in general, is not present in the EnterStuff method.  It is important to consider the case where the user just hits 'enter' and doesn't give you a name.  What happens?  Your program currently accepts that and continues on.  At the very minimum you should always check if the input string has length()==0, and if it does, reprompt for the data.
    • You write your data to files based on the name input.  However, you never check if a file with that name already exists.  You should always verify that you are not overwriting existing data with new data.  If there is already a file with that name, you need to prompt the user whether or not the file should be overwritten. (also as a side note to this, you request the name in the form "Last, First', and then use that as the filename under which to store the data, filenames with commas and spaces in them may not work on all systems.. and just seems a little weird to me.. but that's a nitpick that may not be valid, as it seems to work on both Winders and Linux for me... but, it is another case where you have to be careful about user input because they could just as easily type Last; First which will not work)
    • When reading/writing to the file, you catch the IOException that may be thrown, but you don't report the error to the end user.  An error message that simply says 'failed' is no help to anyone.  At the very minimum, you should be printing the 'getMessage()' from the exception along with your failure message... (oh, and don't shout at the user, all caps in messages isn't necessary and is considered bad form)

    I think that's all the critique I have.  I hope it was strong enough ;) 



  • there's no WTFs that I can see. However there is one thing, I would like to introduce you to a new concept called commenting. It helps others read and understand your code.

    Also split long line up across multiply lines. i.e

    new PrintStream(fout).println ("NAME: "+ Name + ";" + "ADDRESS: " +
    Address + ";" +
                    "JOB: " + Job + ";" + "MATERIAL COST:" + MatCost + ";"
    +
                    "LABOR COST: " + LabCost + ";" + "TOTAL COST: " + TotalCost);

     



  • As most have already said, the labeled continue is very much pointless, not only in this case (because it points to the top of the loop, which is where continue; would go anyway), but quite likely in 99,9% of all programming cases.

    There's an if-else-if chain with value comparisons. I generally prefer to replace that with a switch statement. In this case, it'd probably not make any difference for efficiency, but a switch does compile to different code, and it fist better with the spirit of what the if-else-if is supposed to do. If the chain gets much longer, replace it with named commands. I have this personal thing against checking values. :)

    Some exta whitespace would go a long way:

    Not this: (MatCost*1.0825)+LabCost;
    But this: (MatCost * 1.0825) + LabCost;

    I tend to put a whiteline between bits of setup, data gathering, data processing, and actual execution (the business logic, if you will). Something like this:

            InputStreamReader converter = new InputStreamReader(System.in);
            BufferedReader in = new BufferedReader(converter);

            System.out.println("ENTER NAME(LAST, FIRST):");
            String Name = in.readLine();

            System.out.println("ENTER MATERIAL COST:");
            double MatCost = Double.parseDouble(in.readLine());

            System.out.println("ENTER LABOR COST:");
            double LabCost = Double.parseDouble(in.readLine());

            try {
                FileOutputStream fout;
                fout = new FileOutputStream (Name + ".txt");
                new PrintStream(fout).println ("NAME: "+ Name + ";" + "ADDRESS: " + Address + ";" + "JOB: " + Job + ";" + "MATERIAL COST:" + MatCost + ";" + "LABOR COST: " + LabCost + ";" + "TOTAL COST: " + TotalCost);
                fout.close();
                System.out.println("\nINFORMATION STORED.\n");
            }

            catch(IOException e) {
                System.out.println("\nCOULD NOT STORE INFORMATION.\n");
            }

    Be kind to your readers (including the future you). Compressing code never helped anyone.

    And a minor point on the ALL-CAPS OUTPUT MESSAGES. That's not necessary :) 



  • Just two things:

    1.  YOU SOUND LIKE YOU ARE SHOUTING EVERYTIME YOU ASK THE USER FOR INPUT.  Users don't like being shouted at.

    2.  You don't check for semicolons in the user's input.  It would screw the app up if my job title was "Lead Developer; Sales Manager".  This wouldn't likely occur in a production app, but since this is an assignment, your teacher will notice.



  • [quote user="dhromed"]There's an if-else-if chain with value comparisons. I generally prefer to replace that with a switch statement. In this case, it'd probably not make any difference for efficiency, but a switch does compile to different code, and it fist better with the spirit of what the if-else-if is supposed to do.[/quote]

    This being Java, you can't switch on strings.  You have to use if/else chains or go straight to a map of names to command objects, barring insane reflection hacks (don't do this).

    A few minutes with a code beautifier would help the OP's program immeasurably.

     



  • I didn't see the forest for the trees.

    1. Don't store computed values.  Recompute them, so you know they're valid given the source data.
    2. Don't use floating point types to store money in real applications.  Rounding errors will kill you dead.



  • Just for grins, I deduced what your assignment might be and banged away at it until I got bored.  Anyone mind giving me a similar review of this code?



  • here's a how I would implement such a program:

    import java.io.BufferedReader;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;

    public class TowerOfHanMain {
        
        /
         * Get input from a stream
         *
         * @param in - Stream to read
         * @param msg - message to show to user
         * @param Valid - regular expression to use for validating
         * @return a valid string, that was read from the stream
         * @throws IOException - when an error occured when reading the stream
         /
        private static String getInput( BufferedReader in, String msg, String Valid)
        throws IOException{

            String UserInput;
            do {
                System.out.println(msg);
                UserInput = in.readLine();
            }while (!UserInput.matches(Valid));
            return UserInput;
        }

        /

         * Start Of execution
         *
         * @param args - args past in at prompt
         /
        public static void main (String[] args)
        {
            try{
                String Query;
               
                BufferedReader in =
                    new BufferedReader( new InputStreamReader(System.in));

                do{
                    
                    Query = getInput(in, "\nChoose from these options\n" +
                            "| ENTER | SEARCH | QUIT |", "[\p{Alpha}]+").toUpperCase();
                    
                    if(Query.equals("ENTER"))
                        EnterRecord(in);
                    else if(Query.equals("SEARCH"))
                        SearchRecord(in);
                    else if(!Query.equals("QUIT"))
                        System.out.println("Invalid selection.\n");


                }while(!Query.equals("QUIT"));

                System.out.println("END OF LINE.");    
            }catch (IOException e){
                System.out.println("Error: " + e.getMessage());
            }
        }

        /

         * Create a new record
         *
         * @param in - where to get the data from
         * @throws IOException - if an error occures while reading in writting to the file
         /
        public static void EnterRecord(BufferedReader in)throws IOException{

            String Name = getInput(in,
                                "Enter Name(Last, First):",
                                "[\p{Alpha} ]+[\,]{1}[\p{Alpha} ]+");
            
            String Address = getInput(in, "Enter Address:", "[\p{Alnum} \\]+");
            
            String Job = getInput(in, "Enter Job:","[\p{Alpha}]+");
            
            double MatCost = Double.parseDouble(getInput(in,
                                "Enter Material Cost:",
                                "[0-9]+[\.]{0,1}[0-9]
    "));
            
            double LabCost = Double.parseDouble(getInput(in,
                                "Enter Labor Cost:",
                                "[0-9]+[\.]{0,1}[0-9]"));
            
            double TotalCost = (MatCost
    1.0825)+LabCost;

            try{
                FileOutputStream fout;
                fout = new FileOutputStream (Name + ".txt");
                
                new PrintStream(fout).println ("NAME: "+ Name + ";" + "ADDRESS: " + Address + ";" +
                        "JOB: " + Job + ";" + "MATERIAL COST:" + MatCost + ";" +
                        "LABOR COST: " + LabCost + ";" + "TOTAL COST: " + TotalCost);
                
                fout.close();
                System.out.println("\nInformation Stored.\n");
                
            }catch(IOException e){
                System.out.println("\nCould not store information.\n");
                throw e;
            }

        }

        /**
         * Search for a record
         *
         * @param in - input stream
         * @throws IOException - if an error occures while reading in or while reading a file
         */
        public static void SearchRecord(BufferedReader in)throws IOException
        {
            
            String Name = getInput(in,
                    "Enter Name(Last, First):",
                    "[\p{Alpha} ]+[\,]{1}[\p{Alpha} ]+");
            try{
                FileReader fin = new FileReader(Name + ".txt");

                String[] SplitInfo = new BufferedReader(fin).readLine().split(";");

                for (int i=0; i<SplitInfo.length; i++)
                    System.out.println(SplitInfo[i]);
                fin.close();

            }catch(IOException e){
                System.out.println("\nCould not locate client.\n");
                throw e;
            }
        }
    }

    @Angstrom: your solution is too complex for a simple application like this.



  • I think that the design is a bit off. The data should be stored in an object resident during execution, not explicitly written and read from disk at every operation. An ArrayList of HashMaps, perhaps, would make searching pretty simple. This would allow you to make your program [i]much[/i] more orthogonal (look it up). Also, if something seems hard, there is probably a better way already out there.

    For instance: let's replace this bit of code to split and print the info:

                int count = 0;
                char separator = ';';
                int index=0;
                do                                             
                {
                    ++count;                                
                    ++index;                                
                    index=Info.indexOf(separator, index);
                }    
                while (index!=-1);
                String[] subStr=new String[count];            
                index=0;                                    
                int endIndex = 0;                            
                for (int i=0; i<count; i++)                    
                {
                    endIndex=Info.indexOf(separator, index);
                    if (endIndex==-1)
                        subStr[i]=Info.substring(index);
                    else
                        subStr[i]=Info.substring(index,endIndex);
    
                index=endIndex+1;
            }
            for (int i=0; i&lt;subStr.length; i++)
                System.out.print(subStr[i] + "\n");
    

    With this:

                System.out.print(Info.replace(';', '\n'));
    


  • @baysiqq said:

    I know. :) In the beggining of the course my teacher decided Java was the way to go. I really didn't support his decision.

     

     

    Ahh, Java. What a great language to teach in. It's so easy to just jump in and get started with programming concepts when a "Hello (your name)" app looks like this:

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    

    public class HelloName
    {
    public static void main(String[] args) throws IOException
    {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Please enter your name: ");
    String name = in.readLine();
    System.out.println("Hello, " + name);
    }
    }

    Concepts involved:

    • import statements
    • packages
    • classes
    • the main method
    • the "static" keyword
    • arrays
    • method calling
    • method definition
    • constructors
    • variables and assignment
    • file naming by class name
    • compilation
    • execution

    Now, the equivalent Ruby code:

    puts("Please enter your name: ")
    name = gets()
    puts("Hello, " + name)
    

    Concepts involved:

    • method calling
    • strings
    • variables and assignment
    • execution


  • [quote user="Angstrom"]Just for grins, I deduced what your assignment might be and banged away at it until I got bored.  Anyone mind giving me a similar review of this code?
    [/quote]

    Angstrom, importing your project into eclipse made me happy. Nice solution, complete with documentation and build file. Just currious, how long did that take you to bang out? 



  • Angstrom.

    for all the engineering you did on that you have really terrible input checking:

    Material cost (dollars):
    asdf
    Exception in thread "main" java.lang.NumberFormatException: For input string: "asdf"
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at java.lang.Double.parseDouble(Unknown Source)
    at net.lionsanctuary.gasworks.consoleui.Prompter.promptForDouble(Prompter.java:49)
    at net.lionsanctuary.gasworks.consoleui.JobConsoleIO.readJob(JobConsoleIO.java:39)
    at net.lionsanctuary.gasworks.consoleui.commands.AddJobCommand.applyCommand(AddJobCommand.java:42)
    at net.lionsanctuary.gasworks.consoleui.ConsoleApp.main(ConsoleApp.java:50)



  • Angstrom,

    Another thing. After looking at your code I've decided it suffers from extreme over engineering of a simple problem. I could write a GUI application and better error checking in less lines than that. It is also much harder to read than it needs to be. On the other hand there were a couple goodies in there that I got a kick out of.

    Original poster.

    Don't use hard coded (magic) numbers in your code. the 1.085 or whatever will probably change over time. Have it be read in from file or at the very least declare a static variable for the class and use that as the sales tax. Also it's usually bad form to use exception handling as normal flow control. Instead of just attempting to create the FileInputStream with the filename you should get a list of the files in that folder and do a list() on that directory and checking if that filename exists.



  • Tster, Angstrom clearly states he worked on the app for "fun" until he got bored, not until he met your error checking spec. The day I check my own code I write for fun for retarded user input for "fun" is the day I kill myself. He wrote this for his own edification, and I think it's asinine to check for insane user input when you're the only one intending to ever use the app. Seriously, why would I ever worry that I might enter a letter instead of a number in my own program, unless I was fsking retarded. You sound like a BAD highschool programming teacher and I hate you.



  • [quote user="kaamoss"]Tster, Angstrom clearly states he worked on the app for "fun" until he got bored, not until he met your error checking spec. The day I check my own code I write for fun for retarded user input for "fun" is the day I kill myself. He wrote this for his own edification, and I think it's asinine to check for insane user input when you're the only one intending to ever use the app. Seriously, why would I ever worry that I might enter a letter instead of a number in my own program, unless I was fsking retarded. You sound like a BAD highschool programming teacher and I hate you.
    [/quote]

     Angstrom, also said that he wanted the same type of criticism , as the original poster.



  • [quote user="brendan"]

    [quote user="kaamoss"]Tster, Angstrom clearly states he worked on the app for "fun" until he got bored, not until he met your error checking spec. The day I check my own code I write for fun for retarded user input for "fun" is the day I kill myself. He wrote this for his own edification, and I think it's asinine to check for insane user input when you're the only one intending to ever use the app. Seriously, why would I ever worry that I might enter a letter instead of a number in my own program, unless I was fsking retarded. You sound like a BAD highschool programming teacher and I hate you.
    [/quote]

     Angstrom, also said that he wanted the same type of criticism , as the original poster.

    [/quote]

    Tster's right, the input checking is pretty terrible.  It's also grossly overengineered, hence the "gasworks" package name -- it's a term I picked up somewhere (I would've sworn it was on C2, but neither "gas works" nor "gas factory" show up there now) for what happens when you create a ludicrously complex solution (build a gasworks) to a simple problem (light my room).

    To the guy who asked how long that took -- about two hours.  I started with the OP's code and went kind of insane with the refactoring tools before writing any of my own code.

    It's pretty easy to bolt some input checking into the Prompter class, probably.  I did the simplest thing that could suffice, when I should've done the simplest thing that would work,



  • [quote user="Bob Janova"]

    No WTFs as such, but a few things that mark you out as a newbie (which you are, so it's not too much of a problem).

    • ... 

     And of course The Real WTF (TM) is that you're using Java ;)

    [/quote]

    I'm gunna have to agree with bob here. The last time i wrote a java application it was to parse huge CRLF delimited text files into hash tables and then arbitrarily take them out one at a time. and when i say huge, i mean 10 megs of single words CRLF seperated. it was obnoxious and trivial, and the program looked like it would qualify for "feature creep", "bloatware", and "code that has more comments than code".

    Terrible. I'm very VERY happy with .NET, and if i really feel like writing some fast code i use... get ready to laugh :

    ANSI BASIC -> B2C converter -> Notepad -> GCC

    I hate C for it's IO, and being able to write it in BASIC (which i've been writing stuff in since 1988) makes my life easier. the B2C thing takes care of all IO and memory management, and my algorithms and data structures are converted as a plus!

    I've been meaning to check out J#, i wonder if that's any good?

    Also, as far as the OP's code goes, it looks better than what i would have churned out in a highschool java class. Of course, my highschool CS class was... FORTRAN! HOORAY! we also could have taken Pascal and BASIC. rock on!

     

    --gene



  • @GeneWitch said:

    ANSI BASIC -> B2C converter -> Notepad -> GCC

    ...

    I've been meaning to check out J#, i wonder if that's any good?

    Are you sure you haven't been the subject of a post here yet? If not, I predict it in the near future.

    J# is the bastard child of .NET and J++, with Visual J++ being the demon-spawn of Java and the The Black Goat of the Woods with a Thousand Young, Shub-Niggurath, the wife of the Not-to-Be-Named-One.

    Should you choose to go down that route, may we never speak again, and may God have mercy on your soul.



  • [quote user="djork"][quote user="GeneWitch"]

    ANSI BASIC -> B2C converter -> Notepad -> GCC

    ...

    I've been meaning to check out J#, i wonder if that's any good?

    [/quote]

    Are you sure you haven't been the subject of a post here yet? If not, I predict it in the near future.

    J# is the bastard child of .NET and J++, with Visual J++ being the demon-spawn of Java and the The Black Goat of the Woods with a Thousand Young, Shub-Niggurath, the wife of the Not-to-Be-Named-One.

    Should you choose to go down that route, may we never speak again, and may God have mercy on your soul.

    [/quote]

    My code isn't used in production anywhere except my server and my desktop, and as such if it is WTF'd I'm sure you'd see it here, posted by me. hehe. And since you're willing to sign me off on accuont of J#, i'll take that as a "it sucks"

    and the whole BASIC to C thing... i hate C++ for every reason you can hate a language, but i hate C's (%d, i, "blahblahblah") looking IO much much more. I can edit and optimize C and C++ code, but i refuse to write a program in either language from the get go. give me write() and writeline() any day of the week. (or print, even.)

    My friend who's in the CS field says that it is because i learned BASIC as my first programming language on an Atari and a TI-49A. Then for some reason decided to take up fortran instead of Pascal or C.



  • GeneWitch,

    In another post you said you hated pointers. If I would have read this post first I wouldn't have bothered to ask why.



  • @GeneWitch said:

    and the whole BASIC to C thing... i hate C++ for every reason you can hate a language, but i hate C's (%d, i, "blahblahblah") looking IO much much more. I can edit and optimize C and C++ code, but i refuse to write a program in either language from the get go. give me write() and writeline() any day of the week. (or print, even.)

    Do you really...

    A) think that format strings are exclusive to C, when they exist in numerous languages like C, C++, Java, C#, Perl, Ruby, Python, and yes even Visual Basic

    and

    B) think that they look like (%d, i, "blah blah blah") when it would be more like ("blah blah %d", i)?

    Interesting that you would find more utility in: print "blah: " + x + ", blah: " + y; than in: printf("blah: %d, blah: %d", x, y);



  • No i know they're not exclusive. And by the way... oldschool basic had functions called peek and poke. and i was very young when reading the owner's manuals... they said "poking data to unknown locations may be harmful to the operation of your computer" or something that basically meant "you can crash your system" but that wasn't how it sounded to my 9 year old brain. See, i fried an Atari at a young age trying to get the tape drive feature working, so seeing "this will mess up your computer" left a bad taste in my mouth. Fast forward to highschool where my buddy was taking C courses, talking about pointers... which allowed you to write to memory locations (arbitrarily?) ... That's why i hate pointers; for much the same reason that someone who almost drowned at a young age won't go in the ocean as an adult. :-)



  • @GeneWitch said:

    No i know they're not exclusive. And by the way... oldschool basic had functions called peek and poke. and i was very young when reading the owner's manuals... they said "poking data to unknown locations may be harmful to the operation of your computer" or something that basically meant "you can crash your system" but that wasn't how it sounded to my 9 year old brain. See, i fried an Atari at a young age trying to get the tape drive feature working, so seeing "this will mess up your computer" left a bad taste in my mouth. Fast forward to highschool where my buddy was taking C courses, talking about pointers... which allowed you to write to memory locations (arbitrarily?) ... That's why i hate pointers; for much the same reason that someone who almost drowned at a young age won't go in the ocean as an adult. :-)

    Complete and utter bunk. There is no reason to go on thinking that C allows you to read or write to random memory locations in a modern operating system. Maybe on an embedded system with no memory paging or management otherwise? That's not to say that pointer errors can't give you unxepected results ("random" numbers) or anything. Read up on it here: http://en.wikipedia.org/wiki/Segmentation_fault

    I'm not just trying to rail on you or anything, but if you just get your information straight you will be able to open up a lot of possibilities in programming.



  • [quote user="djork"]

    Complete and utter bunk. There is no reason to go on thinking that C allows you to read or write to random memory locations in a modern operating system. Maybe on an embedded system with no memory paging or management otherwise? That's not to say that pointer errors can't give you unxepected results ("random" numbers) or anything. Read up on it here: http://en.wikipedia.org/wiki/Segmentation_fault

    I'm not just trying to rail on you or anything, but if you just get your information straight you will be able to open up a lot of possibilities in programming.

    [/quote]

    Yah, i've been looking at C++ for a while now (few years, at least)... looks foreign. i even dabbled in java for a while. Right now i am studying data structures, and a while back i read a bunch on algorithms, but those were languageless, so i'd still have to go get a book or something to figure it out in C++. I sort of expect to catch a lot of flak on these forums for my programming styles and habits :-)


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.