Tag Info

Hot answers tagged

71

Code Complete by Steve McConnell. I don't even think it needs explanation. It's the definitive book on software construction. Incredibly well written and covers all aspects of the practical (programming) side of creating software.


39

I'll expand my comment: ... if you're adding or removing elements, you want a list (or other flexible data structure). Arrays are only really good when you know exactly how many elements you need at the start. A Quick Breakdown Arrays are good when you have a fixed number of elements that is unlikely to change, and you wish to access it in a ...


36

The Structure and Interpretation of Computer Programs, aka SICP When I saw that SICP was not listed yet, I grimaced in pain. :) Why: There's nothing more to add to Norvig's praising this book as the greatest introduction to computer science ever written. Well OK, since the Why? was requested: SICP covers the fundamentals of software in a satisfyingly ...


28

Design Patterns: Elements of Reusable Object-Oriented Software This is the book to read on OOP design and architecture. The patterns are good when used properly, but I think the real value of this book is that it gives you a toolbox of ideas to use when designing.


28

Robert C. Martin's Clean Code Languages, frameworks, methodologies come and go, but many ideas in this book are, I suspect, forever.


28

Assuming that you mean "integer" when you say "number", you can use a bitvector of size 2^n, where n is the number of elements (say your range includes integers between 1 and 256, then you can use an 256-bit, or 32 byte, bitvector). When you come across an integer in position n of your range, set the nth bit. When you're done enumerating the collection of ...


25

I just counted my books today. 23 of 'em. It depends on what I'm working on. I guess the timeless answer is "C language", By Kernighan and Ritchie.


19

Working Effectively with Legacy Code by Michael Feathers. It contains many good tips of how to get an existing code base under test and manageable, most of which I didn't know about until I read this book. A must read, even if the legacy code you are working with is your own code that you wrote yesterday.


18

Yes, there are such languages. Many of them. In fact, this feature is pretty much the definition of an array language or vector language. Examples of array and vector languages include, but are not limited to, the APL family of languages with its successors, derivatives and cousins (E.g. APL, J, K) and pretty much all mathematical and statistical languages ...


17

I'll expand my comment a bit. The List[T] data structure, from scala.collection.immutable is optimized to work the way an immutable list in a more purely functional programming language works. It has very fast prepend times, and it is assumed that you will be working on the head for almost all of your access. Immutable lists get to have very fast prepend ...


16

While there can be exactly one max value in a collection, there can be more than item representing that value. E.g {1, 9, 2, 9, 0} has max value of 9, represented by both elements [1] and [3]. Note that not all collections support index access; e.g. a Set<Integer> can have a meaningful maximum but accessing an element by index makes no sense in it. ...


15

The must-have Java books: Effective Java By Josh Bloch Java Concurrency in Practice By Brian Goetz, et. al. Java Puzzlers By Josh Bloch, Neal Gafter


12

Lists are much more versatile than arrays. With lists, you can recurse (e.g., for mapping or folding) by cdring down a list. This doesn't work for arrays; you'd have to pass in the array index too. For example, this is a simple implementation of map and fold that take one list only: (define (map1 f l) (if (null? l) l (cons (f (car l)) (map1 f (cdr ...


11

Coders at work by Peter Seibel Interesting and inspiring, highly recommended.


11

The most important factor is that you can prepend to an immutable singly linked list in O(1) time, which allows you to recursively build up n-element lists in O(n) time like this: // Build a list containing the numbers 1 to n: foo(0) = [] foo(n) = cons(n, foo(n-1)) If you did this using immutable arrays, the runtime would be quadratic because each cons ...


11

How do you propose the head be reached in this reversed list? If not using mutable structures the reversed list would only be performant if you made the head linear time and tail constant. But now you've got the exact same structure as before except you're calling the head the tail and vice versa. the structure is the way it is because regardless of which ...


10

A generic queue or array is generally not, by itself, thread safe, just like many other data types. Thread safety is usually accomplished in two ways: Using mutex locks - each thread that wants to modify a value has to wait. Delegation - only the owning thread can modify the value. Mutex locks are fairly straight forward - nobody owns the value, but only ...


9

If by "best" you actually mean "fastest", then by far the fastest way (although not nearly the most efficient way) is to choose a multiplier that makes all of the weights integers, at least to whatever precision you care about, and then store that many copies of each in one large array. For example, if you assign "score multiplier" a weight of 80%, and ...


8

Even more, C++ have such functions, take a look to algorithm (or with C++11 additions) header: std::transform std::for_each std::remove_copy_if They can be easily used with any container. For example your code can be expressed like this (with C++11 lambdas for easy coding): std::vector<int> x = {1, 2, 3, 4, 5}; std::vector<int> y; ...


7

Consider the problem of manipulating a list into a different state where you know the end state. Find each 'enclosed subgraph' bigger than one (I'll explain this later on). Find the sum of the lengths of the subgraphs and subtract the number of subgraphs. There's your answer for the number of swaps. An 'enclosed subgraph' is a minimal subset of the whole ...


6

Python actually supports insertion of arbitrary sub-lists, as a part of list slice assignment. You just assign to an empty slice before the element where you want to insert a new list: list1 = [1, 2, 3] list1[1:1] = [10, 20, 30] # insert 3 elements at index 1 print list1 # prints [1, 10, 20, 30, 2, 3] Many languages view lists as primarily sequential ...


5

The Pragmatic Programmer: From Journeyman to Master (Andrew Hunt and David Thomas)


4

Getting Things Done (David Allen) teaches you how to deal with the thousands of small tasks you need to accomplish in your day-to-day job as a software developer. Although it is not specifically geared towards developers, it is definitely an invaluable aid, as software development typically involves a very large number of small tasks that need to be done in ...


4

I think it comes down to lists being rather easily implemented in functional code. Scheme: (define (cons x y)(lambda (m) (m x y))) Haskell: data [a] = [] | a : [a] Arrays are harder and not nearly as pretty to implement. If you want them to be extremely fast then they'll have to be written low-level. Additionally, recursion works much better on ...



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