• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

PK Gaming

Member
for loops.

Code:
for(i = 0; i < size of array - 1; i++)
{
    // use scanf to get use input
    // store user input in i position of array
    // print array contents here, or outside of loop. Use another for loop
    for (i = 0; i < size of array - 1; i++)
    {
         // print array contents at i
    }
}

Super simple way of doing it. I'm sure there's other ways out there that are probably more elegant.

Thank you, this helped me out immensely
 
Any of you guys know anything about search?

I'm working on a project using Cassandra as the database at the moment. It's a simple social network type of thing. I am at the point where I need to implement a basic search for users and I know Cassandra/bigtable is just completely incapable of doing this. Anyone know what the best solution for this sort of thing is? I did some research and it seems that apache lucene and solr seem to be the tools for the job, but they seem really overkill for a simple user search. As of right now my decision has been to use MySQL to just do some basic index tables and then use a levenshtein distance function to get some basic results.
 

Sharp

Member
Any of you guys know anything about search?

I'm working on a project using Cassandra as the database at the moment. It's a simple social network type of thing. I am at the point where I need to implement a basic search for users and I know Cassandra/bigtable is just completely incapable of doing this. Anyone know what the best solution for this sort of thing is? I did some research and it seems that apache lucene and solr seem to be the tools for the job, but they seem really overkill for a simple user search. As of right now my decision has been to use MySQL to just do some basic index tables and then use a levenshtein distance function to get some basic results.
Postgres full text search is actually quite good, and built into the database. I'd use that if you just want to get something up and running (assuming you have full control over your stack). I wouldn't recommend MySQL for new projects (it does have builtin FTS but it's not very good, same with SQL Server in this case). Curious whether you really need Cassandra--most of the time it's overkill.
 

Ya no

Member
Hey guys, I'm learning mySQL and need help with foreign keys. Say there is two tables members and groups linked with a bridge table members_groups. The only things in the members_groups table is member_id and group_id (the primary keys the two other tables). I'm supposed to write a script that creates the members_groups table, but I'm stuck on how to do foreign keys.

Would it be something like :

Code:
CREATE TABLE members_group (
member_id INT REFERENCES members (member_id),
group_id INT REFERENCES groups (group_ID)
);
 
Postgres full text search is actually quite good, and built into the database. I'd use that if you just want to get something up and running (assuming you have full control over your stack). I wouldn't recommend MySQL for new projects (it does have builtin FTS but it's not very good, same with SQL Server in this case). Curious whether you really need Cassandra--most of the time it's overkill.

I'll take a look at postgres, but at this point I don't really need the full text search, just some fuzzy lookups of names. If it has better builtin search than MySQL though it could be worth investigating.

As far as why Cassandra, I'm coding this as a startup. I'm actually planning on running with this project and seeking funding, and I'm going to shop it at various incubators. I want it to be something I can say with confidence is ready for a production level environment with tens of thousands of simultaneous users. I've got full control of the stack as this is my project. I just don't have a ton of experience with search, so I've gotta do some homework on it.
 
Hey guys, I'm learning mySQL and need help with foreign keys. Say there is two tables members and groups linked with a bridge table members_groups. The only things in the members_groups table is member_id and group_id (the primary keys the two other tables). I'm supposed to write a script that creates the members_groups table, but I'm stuck on how to do foreign keys.

Would it be something like :

Code:
CREATE TABLE members_group (
member_id INT REFERENCES members (member_id),
group_id INT REFERENCES groups (group_ID)
);

http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

If you check that out about half way down the page it has an example of how to create foreign keys.
 

Sharp

Member
I'll take a look at postgres, but at this point I don't really need the full text search, just some fuzzy lookups of names. If it has better builtin search than MySQL though it could be worth investigating.
You will be less happy in general with MySQL than PostgreSQL. Most active relational database research happens there first (e.g. serializable snapshot isolation, jsonb indices), its query parser is much more compliant, it has a much stronger track record for reliability, it has a much better query planner, and it improves substantially with every release (full disclosure: I have contributed to the project).
As far as why Cassandra, I'm coding this as a startup. I'm actually planning on running with this project and seeking funding, and I'm going to shop it at various incubators. I want it to be something I can say with confidence is ready for a production level environment with tens of thousands of simultaneous users. I've got full control of the stack as this is my project. I just don't have a ton of experience with search, so I've gotta do some homework on it.
You can get surprisingly far before you really need tens of thousands of simultaneous open database connections (NeoGAF has much fewer than that at any one time) and much further than that before you can't get away with standard read replicas and need a database like Cassandra. If you really want to have high reliability in the face of huge traffic, choosing Cassandra is just the first of many decisions you'll need to make, as it will inform every decision you make with your application. Some examples: how does your application deal with machine death and failover? Load balancing? Will you use an addressing system that abstracts physical addresses? How will you handle DOS attacks? Where and how will you handle consistency vs latency tradeoffs throughout your application? How will you stage release rollouts? If you can't answer those questions, choosing Cassandra may be premature. It's a fantastic database, but it's designed for extreme environments so you really need to make sure you have a usecase for it.
 
You will be less happy in general with MySQL than PostgreSQL. Most active relational database research happens there first (e.g. serializable snapshot isolation, jsonb indices), its query parser is much more compliant, it has a much stronger track record for reliability, it has a much better query planner, and it improves substantially with every release (full disclosure: I have contributed to the project).

You can get surprisingly far before you really need tens of thousands of simultaneous open database connections (NeoGAF has much fewer than that at any one time) and much further than that before you can't get away with standard read replicas and need a database like Cassandra. If you really want to have high reliability in the face of huge traffic, choosing Cassandra is just the first of many decisions you'll need to make, as it will inform every decision you make with your application. Some examples: how does your application deal with machine death and failover? Load balancing? Will you use an addressing system that abstracts physical addresses? How will you handle DOS attacks? Where and how will you handle consistency vs latency tradeoffs throughout your application? How will you stage release rollouts? If you can't answer those questions, choosing Cassandra may be premature. It's a fantastic database, but it's designed for extreme environments so you really need to make sure you have a usecase for it.

I definitely appreciate where you're coming from. I've got production level experience with all of those things in my professional career. The most honest answer I can give as to why cassandra is because I'm experienced with it and greatly enjoy using it, aside from the practical reasons as to why, which I have plenty of. I've got plenty of experience with SQL Server and MySQL as well, and I just don't think they would fit the environment as ideally as Cassandra does, and in so many ways cassandra is far easier to use.
 

ChrisD

Member
Two/Three part question for ya', ProGrAF.

Has anyone had any experience with Sams Teach Yourself C++ in 21 Days... from 1999? (Mother bought it because it was cheap >_>)

Second part, does anyone have experience with the Seventh Edition?

Lastly, should I even bother with it, or wait 'til I can scrounge the money together for that C++ Primer Plus book everyone seems to love? Is it a case of "learn right or not at all" or "any learning is better than none." I know that coding is something you likely don't want a fifteen year old book to learn with since it's evolved so much, which is why I ask. Don't want to fill my mind with things that may end up confusing me later on because I learned from an old book.
 
Two/Three part question for ya', ProGrAF.

Has anyone had any experience with Sams Teach Yourself C++ in 21 Days... from 1999? (Mother bought it because it was cheap >_>)

Second part, does anyone have experience with the Seventh Edition?

Lastly, should I even bother with it, or wait 'til I can scrounge the money together for that C++ Primer Plus book everyone seems to love? Is it a case of "learn right or not at all" or "any learning is better than none." I know that coding is something you likely don't want a fifteen year old book to learn with since it's evolved so much, which is why I ask. Don't want to fill my mind with things that may end up confusing me later on because I learned from an old book.

I am actually pretty sure I used that same book... back in like 2000. I was finishing high school and had a few programming courses, liked them, and decided I'd do a program as my graduation project and I did it in C++. I ended up winning the award (and a savings bond!) for the best project in my graduating class for the program. That's about the only thing I remember about the entire book! All I can say is that the fundamentals of C/C++ have not changed overly much since that point in time. I am sure it's far from the best resource available anymore but I am sure there are things of value in there to learn from.

The big question I have for you is, are you doing this to learn programming, or are you doing it to learn C++? If you're doing it to learn Programming I want to encourage you to give Python or another language a shot before C++.
 

mltplkxr

Member
Any of you guys know anything about search?

I'm working on a project using Cassandra as the database at the moment. It's a simple social network type of thing. I am at the point where I need to implement a basic search for users and I know Cassandra/bigtable is just completely incapable of doing this. Anyone know what the best solution for this sort of thing is? I did some research and it seems that apache lucene and solr seem to be the tools for the job, but they seem really overkill for a simple user search. As of right now my decision has been to use MySQL to just do some basic index tables and then use a levenshtein distance function to get some basic results.

It's not hard to get a working prototype running with solr, it's pretty much pre-configured. There's also a lot of documentation and help available because it's so widespread. Getting it in there early will payoff when you need to refine the search or scale it.
 

hateradio

The Most Dangerous Yes Man
GUYS WE MADE IT, WE'RE GOING TO HIT 200 PAGES! Finally, a new OT.


PS: What do most people use to access remote databases from an Android system?
 

ChrisD

Member
The big question I have for you is, are you doing this to learn programming, or are you doing it to learn C++? If you're doing it to learn Programming I want to encourage you to give Python or another language a shot before C++.

Programming is the intended goal. An interest in computer apps and in-general games for the "for myself" intentions, and an eye on the future with (hopefully) a goodish job for the more important intention.

I went through the first chapter in the book Learning Python the Hard Way about two years ago, but dropped it promptly for my school. Now I'm eighteen and am in that confusing position of what to do for college, job, and future... Or in other words, I'm at home all day while I wait for Spring Semester. I remember back then it was considered one of the best resources out there due to the fact it was 1.) well-written, and 2.) entirely free. Is it still considered one of the better ones out there for someone who has never really gone past a "Hello World!"?

I'd really rather hold off on college for the time being. I want to get a GED, get a job, and help my dad out with all the stress he's carrying. Family of six to care for, he's the only one making an income, and it's shaky, sometimes missing a week at random. They want me to continue an education for the future, but I want to help my dad in the now. So I figured... Math and programming are two things that can be done at home while holding an entry-level job.

Blabbered a bit more than you asked. Sorry. Bullet-point version:

-Looking to program, not so much learn C++
-Used Learning Python the Hard Way in the past, but not past chapter one
-Am interested on the general opinion of the book now, two years later
 
Programming is the intended goal. An interest in computer apps and in-general games for the "for myself" intentions, and an eye on the future with (hopefully) a goodish job for the more important intention.

I went through the first chapter in the book Learning Python the Hard Way about two years ago, but dropped it promptly for my school. Now I'm eighteen and am in that confusing position of what to do for college, job, and future... Or in other words, I'm at home all day while I wait for Spring Semester. I remember back then it was considered one of the best resources out there due to the fact it was 1.) well-written, and 2.) entirely free. Is it still considered one of the better ones out there for someone who has never really gone past a "Hello World!"?

I'd really rather hold off on college for the time being. I want to get a GED, get a job, and help my dad out with all the stress he's carrying. Family of six to care for, he's the only one making an income, and it's shaky, sometimes missing a week at random. They want me to continue an education for the future, but I want to help my dad in the now. So I figured... Math and programming are two things that can be done at home while holding an entry-level job.

Blabbered a bit more than you asked. Sorry. Bullet-point version:

-Looking to program, not so much learn C++
-Used Learning Python the Hard Way in the past, but not past chapter one
-Am interested on the general opinion of the book now, two years later

http://www.codecademy.com/en/tracks/python

Do that. Give it a shot, stick with it for at least a week. It will slowly walk you through not just python, but the fundamentals of computer science. I think by the end of it you'll answer a lot of questions as to whether or not you want to pursue computer science, and if you do you'll have a bit of a head start if you go to college for it or even purchase a book for it.

I recommend python because the syntax is pretty simple, but the language has a lot of depth. It's a language that is rapidly gaining in popularity and you'd be able to find jobs using it. C++ can expose you to a lot of complicated things about programming that while they are important, they can hamper the overall learning process.
 

Harpuia

Member
I'm wondering if this is an OK place to do it, but here goes. My question concerns assembly language, more specifically, MIPS. So if I wanted to access some memory address, knowing beforehand where exactly we would like to manipulate, how would I do this? It's not a pointer, but just some address where we want to mess around with the value stored there in memory.
 

arit

Member
I'm wondering if this is an OK place to do it, but here goes. My question concerns assembly language, more specifically, MIPS. So if I wanted to access some memory address, knowing beforehand where exactly we would like to manipulate, how would I do this? It's not a pointer, but just some address where we want to mess around with the value stored there in memory.

Code:
lw	$t0-9, memory adress
do stuff on $t0-9
sw	$t0-9, memory adress

It has been a few years since I last looked at MIPS assembly, might be that I forgot about the existence of operations on memory besides loading and storing.
 

Harpuia

Member
Code:
lw	$t0-9, memory adress
do stuff on $t0-9
sw	$t0-9, memory adress

It has been a few years since I last looked at MIPS assembly, might be that I forgot about the existence of operations on memory besides loading and storing.

I think the thing is the address isn't explicitly stored anywhere in the code. That being said, is addi $t0, $t0, 0xAAAA OK to do?
 
Does anyone have any experience in socket programming in python? I am trying to make an FTP client but am having some issues. The code below lets me communicate with the test FTP server I am using and I am able to send the username, password, and ask for the working directory. However, the connection disconnects immediately after the last line. Does anyone know how I can maintain a connection?
 
Does anyone have any experience in socket programming in python? I am trying to make an FTP client but am having some issues. The code below lets me communicate with the test FTP server I am using and I am able to send the username, password, and ask for the working directory. However, the connection disconnects immediately after the last line. Does anyone know how I can maintain a connection?

It's not really socket specific, I'm pretty sure it's just that the process is ending and so abandoning the socket. You should just need to add a loop that will request user input until an exit command is given, then close the connection when done. You can handle each individual ftp command based on the user command entered each time.
 

Vire

Member
Hey GAF,

I've been stuck on this assignment for hours now and I'm looking for any help! Please!

Code:
// Import Scanner
import java.util.Scanner;

public class Assignment6 {
    

    public static void main(String[] args) {
        
        // Declare variables
        Scanner input = new Scanner(System.in);
        // An array that stores the first item selection
        int[] naItemSelection = new int [13];
        int[] naItemPrice = new int[13];
        
        int nIndex = 0;
      
        // An string that stores the users' name
        String sName;
        // An index to store the first array's values
      
        
        
        // Print out question asking for users' name
        System.out.print("Please enter your name: ");
        // Read in users' name
        sName = input.nextLine();
        
        // Print out blank line
        System.out.println("");
       
        // Print out menu 
        System.out.println("BEST PURCHASE PRODUCTS");
        System.out.println("1. Smartphone       $249");
        System.out.println("2. Smartphone case  $39");
        System.out.println("3. PC Laptop        $1149");
        System.out.println("4. Tablet           $349");
        System.out.println("5. Tablet case      $49");
        System.out.println("6. eReader          $119");
        System.out.println("7. PC Desktop       $899");
        System.out.println("8. LED Monitor      $299");
        System.out.println("9. Laser Printer    $399");
        System.out.println("10. Complete my order");
    
    
    // If the total amount of items selection is less than the array length, continue running the loop, if the item selection is 10, end the loop.
    for (nIndex=0; (nIndex < naItemSelection.length && naItemSelection[nIndex] !=10);  nIndex++){
        
        if(nIndex==0){
            System.out.print("Please select an item from the menu above: ");
            naItemSelection[nIndex] = input.nextInt();
            
            //If Item Selection in the array is input to 10, break
            if(naItemSelection[nIndex]==10){
                break;
        }//end if
            
        }//end if
        
        else {
        System.out.print("Please select another item from the menu above: ");
        
        naItemSelection[nIndex] = input.nextInt();
        
        //If Item Selection in the array is input to 10, break
            if(naItemSelection[nIndex]==10){
                break;    
        }//end if          
        
        }// end else if
      
               
    }//end for loop for prompt user
    
    
    
    //Call method to calculate item price passing array of item selection
    naItemPrice = methodItemPrice(naItemSelection);
    
    //print item price
    
     
            System.out.println("Item Price: " +
                               naItemPrice[nIndex]);
      
    
     
    }//end main
    
    /**
     * Calculates total item price
     * @param naNewItemSelection
     * @return The calculated item price
     */
    
    public static int [] methodItemPrice(int naNewItemSelection[]){
        //Define local variables
        
        int[] naNewItemPrices = new int[13];
        int nCount = 0;
        
        for (nCount = 0; nCount < naNewItemSelection.length; nCount++) {
	  	
               if(naNewItemSelection[nCount] == 1){
               naNewItemSelection[nCount] = 249;  
                
               }//end if
               
               else if(naNewItemSelection[nCount] == 2){
               naNewItemSelection[nCount] = 39;  
               
               } // End else if statement
               
               else if(naNewItemSelection[nCount]== 3){
               naNewItemSelection[nCount] = 1149;
               }
     
             // End if statement

//etc 

//Calculate Item Price
        naNewItemPrices[nCount] = naNewItemPrices[nCount]+naNewItemSelection[nCount];

    } //end for
        
        
        return naNewItemPrices;
    } //end method
    
    
}

I know this is incorrect because I need Item Prices to be returned as a singular int instead of an array.

The problem is, Java won't let me set an int = to the sum of array. Any help would be super duper appreciated.
 

poweld

Member
Hey GAF,

I've been stuck on this assignment for hours now and I'm looking for any help! Please!

If you problem is figuring out how to sum the elements of an array of integers in Java, you will want to use a `for` loop to iterate over the elements of the array, adding each element to a new integer value, 'sum'. Return 'sum' as the result.
 

Vire

Member
If you problem is figuring out how to sum the elements of an array of integers in Java, you will want to use a `for` loop to iterate over the elements of the array, adding each element to a new integer value, 'sum'. Return 'sum' as the result.

Thanks for the response! Hmm, I thought I already put the calculation in a for loop?

Code:
 for (nCount = 0; nCount < naNewItemSelection.length; nCount++) {
	  	
               if(naNewItemSelection[nCount] == 1){
               naNewItemSelection[nCount] = 249;  
                
               }//end if
               
               else if(naNewItemSelection[nCount] == 2){
               naNewItemSelection[nCount] = 39;  
               
               } // End else if statement
               
               else if(naNewItemSelection[nCount]== 3){
               naNewItemSelection[nCount] = 1149;
               }
     

//Calculate Item Price
        naNewItemPrices[nCount] = naNewItemPrices[nCount]+naNewItemSelection[nCount];

 } //end for
        
        
        return naNewItemPrices;
    } //end method

However, when I change naNewItemPrices to a regular integer named sum, I get an error stating:

incompatible types: int cannot be converted to int[]

so it looks like this:

Code:
 Sum = Sum+naNewItemSelection[nCount]

    } //end for
        
        
        return Sum;
    } //end method
 
Thanks for the response! Hmm, I thought I already put the calculation in a for loop?

Code:
 for (nCount = 0; nCount < naNewItemSelection.length; nCount++) {
	  	
               if(naNewItemSelection[nCount] == 1){
               naNewItemSelection[nCount] = 249;  
                
               }//end if
               
               else if(naNewItemSelection[nCount] == 2){
               naNewItemSelection[nCount] = 39;  
               
               } // End else if statement
               
               else if(naNewItemSelection[nCount]== 3){
               naNewItemSelection[nCount] = 1149;
               }
     

//Calculate Item Price
        naNewItemPrices[nCount] = naNewItemPrices[nCount]+naNewItemSelection[nCount];

 } //end for
        
        
        return naNewItemPrices;
    } //end method

However, when I change naNewItemPrices to a regular integer named sum, I get an error stating:

incompatible types: int cannot be converted to int[]

so it looks like this:

Code:
 Sum = Sum+naNewItemSelection[nCount]

    } //end for
        
        
        return Sum;
    } //end method

Did you change your function signature to match your return type?

i.e. public static int [] functionName() should just be public static int functionName()
 

Vire

Member
Did you change your function signature to match your return type?

I'm not exactly sure what you mean but I changed this in main so it looks like this:

Code:
    FinalSum = methodItemPrice(naItemSelection);

 System.out.println("Item Price: " +
                               FinalSum);
and this

Code:
public static int [] methodItemPrice(int naNewItemSelection[]){

However, I get the same error as I was getting down below on the return line.

i.e. public static int [] functionName() should just be public static int functionName()

EDIT: OOOOOH, wow okay. Thank YOU! Such a simple little error driving me nuts. GOT IT! :D
 
It's not really socket specific, I'm pretty sure it's just that the process is ending and so abandoning the socket. You should just need to add a loop that will request user input until an exit command is given, then close the connection when done. You can handle each individual ftp command based on the user command entered each time.

Thanks, added the loop and now I stay connected. Ran into another problem though. I started setting up the user commands. I can send them and the server gets them but say when I send a 'LIST' command the server responds telling me it couldn't establish a data connection. I know I probably have to do a data socket but I haven't a clue how to do it. I send the TYPE and PASV commands to the server and it responds back with the IP address and port but I don't know how to have my client bind to that so that the data connection can be established.
 

Mathaou

legacy of cane
I'm learning Java right now in a computer science class, while loops are confusing me. I have this segment of code, but when I hit run, it skips over the while loop and goes right to the final println statement. I'm doing it like the book showed me, why isn't it working?
Code:
            boolean tripOver = false;
            while (tripOver = false){
			System.out.println("Import the number of miles driven: ");
			milesDriven = input.nextInt();
			System.out.println("Import the number of gallons used: ");
			gallonsUsed = input.nextInt();
			System.out.println("-----------------------------------");
			System.out.println();
			milesPerGallon = milesDriven / gallonsUsed;
			System.out.println("Your gas mileage was " + milesPerGallon + " MPG");
			totalMPG = totalMPG + milesPerGallon;
			System.out.println("Your total MPG was: " + totalMPG);
			System.out.println("Are there any more trips? y for Yes and n for No: ");
			over = input.next();
			if (over == "y")
				tripOver = true;
		}	
             System.out.println("You done, son.");
 
I'm learning Java right now in a computer science class, while loops are confusing me. I have this segment of code, but when I hit run, it skips over the while loop and goes right to the final println statement. I'm doing it like the book showed me, why isn't it working?

while (tripOver = false)

should be

while (tripOver == false)
 
^ If it skips over the while loop, I'd say look carefully at that line and compare it to how other while() lines are written.

Edit:
Doh giving mathaou the answer. Shoulda let her/him sweat that out a bit. Those make great lightbulb moments.
 

PFD

Member
Is Objective-C a good language to learn as a novice programmer? I've taken one Java course in the past, and I'm familiar with concepts like objects, methods, and classes.

The reason I'm learning Objective-C is I want to create some iOS apps.
 

Kalnos

Banned
Is Objective-C a good language to learn as a novice programmer? I've taken one Java course in the past, and I'm familiar with concepts like objects, methods, and classes.

The reason I'm learning Objective-C is I want to create some iOS apps.

Learning any language you're interested in is a good idea. Might want to take a look at Swift too for iOS programming.
 
while (tripOver = false)

should be

while (tripOver == false)

I prefer using

while(!tripOver)

Basically "while not tripOver".

When you are using boolean types you don't need to actually have an equality in the condition. The condition evaluates to a boolean anyway. You can just use the boolean itself, or add negation/not (!) to it. It's short hand, more readable, and can prevent that error where you do assignment rather than comparison.
 
I prefer using

while(!tripOver)

Basically "while not tripOver".

When you are using boolean types you don't need to actually have an equality in the condition. The condition evaluates to a boolean anyway. You can just use the boolean itself, or add negation/not (!) to it. It's short hand, more readable, and can prevent that error where you do assignment rather than comparison.

I would argue that (!tripOver) is error prone as well since it would be easy to overlook the !. Comparing tripOver to true or false provides additional info about the programmer's intent.

Horses for courses of course :)

Anyways, does Java not warn about this? My C++ compiler catches these.
 

Slavik81

Member
Ugh. Why is ruby hitting ssl errors when http.get'ing itself? Browsing my site externally serves up a valid certificate.

I don't even know where to begin to debug this.
 
I would argue that (!tripOver) is error prone as well since it would be easy to overlook the !. Comparing tripOver to true or false provides additional info about the programmer's intent.

Horses for courses of course :)

Anyways, does Java not warn about this? My C++ compiler catches these.

That's why you need well named variables. When it's called "tripOver" you understand the meaning. By inferring what the code is trying to do it highlights the ! for me. But you're right, to each his own.

All modern IDEs give you a warning as far as I remember.
 

hateradio

The Most Dangerous Yes Man
I would argue that (!tripOver) is error prone as well since it would be easy to overlook the !. Comparing tripOver to true or false provides additional info about the programmer's intent.

Horses for courses of course :)

Anyways, does Java not warn about this? My C++ compiler catches these.
Java doesn't warn you against it except if the variable wasn't initialized.

Ugh. Why is ruby hitting ssl errors when http.get'ing itself? Browsing my site externally serves up a valid certificate.

I don't even know where to begin to debug this.
What kind of error are you getting?
 

maeh2k

Member
I would argue that (!tripOver) is error prone as well since it would be easy to overlook the !. Comparing tripOver to true or false provides additional info about the programmer's intent.

Horses for courses of course :)

Anyways, does Java not warn about this? My C++ compiler catches these.

You could also switch the logic around. Just call the variable 'notTrippedOver'.
Or (if the condition is slightly less trivial) just extract a method boolean isNotTrippedOver() { return !tripOver; }

Java IDEs may well be able to warn you. E.g. in IntelliJ IDEA there's a very long list of inspection settings where you specify what you'd like to be warned of.

IMO, if you need to write variable == true to make your intent clear, the problem lies with the naming of the variable. Rename the variable to make the condition read like a sentence.


Edit: another way to avoid these kinds of mistakes is to place the constant on the left, since you cannot assign anything to a constant (true == variable).
 
I'm feeling kinda motivated to revisit my senior project, clean it up, fix some small bugs,port to iOS, and create an online database for it, but goddamned if I'm not overwhelmed with the garbage I produced in the crunch time before I had to present.

plus it's a decent idea that I would actually use.

actually it may be easier and quicker to rip some of the important classes and restart everything else...
 
You could also switch the logic around. Just call the variable 'notTrippedOver'.
Or (if the condition is slightly less trivial) just extract a method boolean isNotTrippedOver() { return !tripOver; }

Java IDEs may well be able to warn you. E.g. in IntelliJ IDEA there's a very long list of inspection settings where you specify what you'd like to be warned of.

IMO, if you need to write variable == true to make your intent clear, the problem lies with the naming of the variable. Rename the variable to make the condition read like a sentence.

Edit: another way to avoid these kinds of mistakes is to place the constant on the left, since you cannot assign anything to a constant (true == variable).

I think 'notTripOver' becomes harder to read further down when it's time to break out of the loop: notTripOver = false; <-- I have to think for a second about what that means.

I agree that variable naming is key. I think something like 'while (tripIsInProcess)' reads well since there is not a negatitive comparison. I'd personally still add the == true in there.

Good call on the (true == variable). I see that occasionally in code bases and just chalked it up to personal style. I can see the validity of using that to reduces errors.
 

phoenixyz

Member
Imo one should rarely use negated boolean variable names as it just lowers readability. If you have something like "inProgress" and you always need to use "!inProgress" then maybe "stopped" or something similar would be better than "notInProgress". As "!inProgress" probably reads "not in progress" in any programmers mind who looks at the code anyway.
Also I think == should be reserved when you actually deal with comparisons. Not when dealing with booleans which have their own operators for a reason (that obviously does not apply to languages like C where there's no dedicated boolean type).
 
Is Objective-C a good language to learn as a novice programmer? I've taken one Java course in the past, and I'm familiar with concepts like objects, methods, and classes.

The reason I'm learning Objective-C is I want to create some iOS apps.

Objective C is kind of a nasty language for a beginner. Swift is probably a bit easier for someone without much programming experience.
 

Husker86

Member
Random question just to feed my curiosity...

What language are things like microwaves and other similar appliances programmed with?
 
Random question just to feed my curiosity...

What language are things like microwaves and other similar appliances programmed with?

Embedded programming is almost exclusively C. C++ is starting to see more use in the last few years I believe and Ada is also used for some application domains (e.g. military airplanes)
 

Mr.Mike

Member
Random question just to feed my curiosity...

What language are things like microwaves and other similar appliances programmed with?

According to my Java textbook, this is what Java was originally meant for, as the JVM was supposed to make it easier to program things for a wide variety of architectures, but it never caught on in that domain. Somehow it caught on in other parts of tech.
 

Slavik81

Member
What kind of error are you getting?
Code:
openssl::ssl::sslerror: ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed
Turns out, though, that I needed to provide intermediate certificates. It worked in my web browser because I happened to already have the missing certificates in my cache just from browsing to other sites that use them. I discovered the problem when other people tried my site through their web browsers and got errors. After inspecting the error generated by chrome on their machine, I managed to figure out their problem. I concaternated the CA's certificates together with mine, making ruby and all other web browsers happy.
 
Top Bottom