Friday, October 14, 2016

That pesky ?: Operator from the Exam!

So far our operator arsenal have been mostly related to arithmetic or booleans. However, there is still a huge library of operators we have yet to learn, and I'm not even sure we'll get to them.
The third bonus question on our midterm, something our professor said we hadn't seen before, asked to explain what the ?: operator was. I'm guessing most of my classmates' responses were identical to mine: "I have no clue," but I'll try to break it down as best I can here.



The ?: operator, or the ternary operator, gives options. For example:

System.out.print("I have " + x + " apple" + (x==1 ? "" : "s");

Essentially, it analyzes a boolean (x == 1) and if it's true (?) it prints nothing after "apple". However, if the boolean is false, the ":" acts as an "else." If you have any amount other than 1 of apples, the correct sentence would be "I have x apples," whether x is less than or greater than 1. There are definitely other ways to do this with if-else statements, but this operator can help us shorten our code.






Image source:
http://stackoverflow.com/questions/19827668/does-java-have-identical-comparison-operator-example

Friday, October 7, 2016

Self-Driving Cars: The Actual Best Option?

People are starting to warm up to the idea of autonomous cars. An initial concern was safety; skeptics weren't sure a car could react to obstacles as quick as a human. However, with our level of programming and technology, safety shouldn't be an issue given normal driving conditions and circumstances. Even before self-driving cars were suggested, manufacturers were implementing automated safety features into newer models of their cars. Lane assist alerted drivers if they were to stray from the middle of the lane. Some lane assists would actually follow the lanes with sensors and move the steering wheel (this isn't exactly self-driving, just assisted driving). Some cars can parallel park on their own, some have blind spot monitoring. However, pure autopilot had yet to be introduced.

Recently, Tesla Motors has led the new self-driving trend. 130 million miles driven after the release, a Tesla driver died in a crash, and Elon Musk insisted that updates to the software would improve safety, even though one crash in 130 million miles is technically safer than the national average, one crash for every 94 million miles.


Safety aside, I'm not so sure I'd use a self-driving feature other than for sleeping. Again, I'm assuming the code guarantees no accident. For one, I enjoy driving, so if I have the option to take control of the car, I will. Further, the self-driving software would work with a GPS to pick the fastest route to the destination. The flaw I see here is that the computer won't weigh options for the smoothest and easiest ride. I'd rather give up two minutes at a red light than go down a road with six sharp speed bumps, but the road with the speed bumps would be more appealing to the computer because it is the shortest distance. Until the computer inside the car can think like a human, I'll keep my hands on the wheel.





References:
http://www.yaleclimateconnections.org/2016/04/electric-cars-pros-cons-and-unknowables/

Images:
http://www.edn.com/design/automotive/4368069/Automobile-sensors-may-usher-in-self-driving-cars

http://www.dailymail.co.uk/news/article-3275167/Self-drive-cars-weeks-Electric-car-maker-Tesla-says-waiting-approval-autopilot-capacity-British-roads.html