Tag Info

Hot answers tagged

52

Expressiveness isn't always a positive language trait in a corporate environment. Java is extremely popular partly because its easy to learn, easy to write, and easy to read. Mediocre programmers can still be very productive in Java, even if their code is wordy and inelegant. Furthermore, it's easy to abuse expressive languages. An expert java programmer ...


51

If cooling is insufficient, the CPU might overheat. But they all (well, at least all modern PC CPUs) feature various thermal protection mechanisms which will throttle the clock speed or, as a final resort, shut down. So yes, on a dusty laptop, 100 % CPU load could cause temporary problems, but nothing will break or "degrade" (whatever that means). For CPU ...


23

A lack of proper input validation is one of those things which tends to lead quite quickly to users doing "bad" things with your application, when it should really be handled by the programmer. I've seen legacy apps where users have been trained to: not enter apostrophes in names not enter any symbol other than a-z0-9, ensure there are no spaces before or ...


20

In Item 5, of Effective Java, Joshua Bloch says The lesson is clear: prefer primitives to boxed primitives, and watch out for unintentional autoboxing. One good use for classes is when using them as generic types (including Collection classes, such as lists and maps) or when you want to transform them to other type without implicit casting (for ...


20

Worry about performance when it becomes a problem. If you write a small app to process 10,000 line files and you get a 1,000,000 line file every 100th file, it probably doesn't matter that it takes longer to process that one file. However, if you are regularly getting files that are 5-10 times larger than initially and your application is taking too long to ...


19

You use do while any time you want the loop to always execute at least once. A typical example of such usage is a command-line interpreter; the command line prompt will always be displayed at least once.


15

Real-world application, reading data from a file in blocks until end of file: do result = readData(buffer) while result != EOF Without do-while you have to do something like result = 0 # magic value that must not be EOF while result != EOF result = readData(buffer) or while true result = readData(buffer) if result == EOF ...


14

There is generally nothing wrong with a program using 100% CPU while it is actually doing useful work and is not taking time away from anything more important. If a particular hardware platform is e.g. only capable of using 100% CPU continuously for one second before it has to throttle back to 50% to avoid overheating, it is generally better for an ...


13

Windows programs (winforms/WPF) should at all times stay responsive. With a naive implementation of a process that uses 100% cpu resources it's all too easy to make your program or even your system seem sluggish and hanging. With a good implementation (for instance: use a seperate thread with lower priority) it shouldn't be a problem. You shouldn't worry ...


10

My main question is when should I trade the easy but somewhat inefficient ways of doing tasks for big giant complicated beasts that do things extremely quickly but destroy any possible ways of upgrading and make the code excessively difficult and prone to rewriting anyway by the next developer? This is usually a false dichotomy. You can ...


10

The standard practice is to go with the primitives, unless you're dealing with generics (make sure you are aware of autoboxing & unboxing!). There are a number of good reasons to follow the convention: 1. You avoid simple mistakes: There are some subtle, non-intuitive cases which often catch out beginners. Even experienced coders slip up and make ...


9

Since if/else is similar to a switch and often interchangeable, your confusion is understandable. Some languages, such as Python, don't even have a switch statement. Not surprisingly, when you Google for "python switch", the first result points to an alternative—a map. Not an if/else, but a map. While you can use if/else every time instead of a switch, you ...


8

Usually I go with the primitives. However, one peculiarity of using classes like Integer and Boolean is the possibility of assigning null to those variables. Of course, this means that you have to do null checks all the time, but still better to get a NullPointerException than to have logic errors due to using some int or boolean variable that has not been ...


8

"modern CPUs are cheap and will degrade quickly at 100% CPU". I don't think anyone's actually addressed the "degrade" part of this question. ICs will degrade when the die temperature exceeds the manufacturer's limits. ICs are usually designed to operate up to 125C, although every 10C increase shortens life by 50% Processors didn't always have thermal ...


7

IMO, it's mostly due to: Poor library support. Sure, there's Quicklisp now, which makes it easy to install libraries, but it doesn't compensate for them being still fairly few, and quite a few are poorly documented or not very well maintained. Compared to Python, there's a good chance that writing non-trivial Lisp application (regardless of the particular ...


6

Almost every program that I write is invoked strictly from the command line. I've also written some fancier things that started out as CLI interfaces and rapidly grew into something more shell like than anything. So, I can speak only for what I know. Here's some common issues with command line programs: Way too many options Unless you are writing a ...


6

I once got a customer support call because my app just disappeared. Turned out they opened another app on top of it. ... I decided not to ensure that didn't happen again, since it was the users computer illiteracy that caused the problem, not the app. Anything I could have done to fix it would have lead to a poor user experience for others.


5

A truism I picked up studying microprocessors in college that stayed with me: "Make the common case fast. Make the uncommon case correct." As long as you have just a small percentage of users choking your code with input two orders of magnitude larger than what it was meant to handle, don't sweat it. Make sure it handles the input correctly if they give ...


5

Why is not Lisp more widespread? If it is really that powerful, people should be using it all over, If you believe that languages are chosen for their technical merits, you are in for a soul-crushing disappointment. Such decisions are made based on Strippers And Steaks. Microsoft can afford them. Oracle can. Sun spent so much money hyping Java that ...


4

I think there are a few reasons why developers tend to only use a few data structures. There are general data structures that work well enough most of the time so they become the primary choice of data structures for most problems. I know hash tables and lists are my "goto" data structures. I even know that in some of the cases I used hash tables when Red ...


4

I have no experience in working for a real company, but I know why LISP has been hard for me to use. First of all, this reminds me of this blog post: http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html The main problem that I have with Lisp is the "which Lisp" question. I usually work on Linux as my main platform, but the things I make ...


4

I think one problem with Lisp not yet mentioned is that for a mediocre or novice programmer (like myself, I freely admit), it can be difficult to see how you turn Lisp code into a big program. It's easy to write but hard to architect. I don't think any of the concepts are particularly difficult, but the DIY mentality is so strong that I often feel at a ...


4

No, switch statements are not generally used wrong. They are mostly used for their intended use: enumerating action alternatives for a smallish set of possible input values. It's more readable then a long if/else chain, compilers can emit very efficient code if the checked values are reasonably contiguous, and it's easier to write error-checking compilers ...


3

I learned LISP a billion years ago in college. LISP, like FORTH, is great for logic. But most programming is not about logic, it's about manipulating data in boring mechanical ways. For example, at the time there as no way to right-justify numeric output. LISP is about nested functionality, and people just don't think that way. They think in terms of DO A, ...


3

Schaum's Outlines series has a book on UML which I found really useful. It has loads of examples and exercises. I was confused about UML too but this book really simplified things. http://www.amazon.co.uk/Schaums-Outlines-UML-Simon-Bennett/dp/0077096738


3

I don't feel like getting specific break/fix examples is as important as realizing this: Users do not read your manual, or watch your tutorials. They learn your software through exploration. If through that exploration they break something, as a programmer it is your job to either warn them of the danger or prevent it from happening in the first place. I ...


3

"..modern CPUs are cheap and will degrade quickly at 100% CPU". You don't have to worry about "CPU degradation" at all. Modern CPUs are not of less quality than in former times. It is very expensive (and is getting more expensive every couple of years) to make CPUs, some billions to build a new fab are not uncommon (see link). ...


3

To play the devil's advocate: In a way, a program that cannot reach 100% utilization could cause worse wear: Unless it is suspended waiting for a keystroke, chances are that it is suspended waiting for disk I/O most of the time. And disks are (still usually) big mechanical devices that are subject to mechanical wear or the risk of shock/gyroscopic effects ...


3

int counter = 0; do { s = Formatter.formatWorkerId(counter++); } while(all.contains(s)); Finds the smallest syntactically correct worker ID that isn't already present in a set. (My uses of do tend to be confined to that kind of problem, where you definitely have to generate a value, but the very first test might already succeed.)


2

I don't think users are stupid. They don't want to use your or any program at all. All they want is to get their things done. Help them and prevent harm from happening to them along the way.



Only top voted, non community-wiki answers of a minimum length are eligible