Tag Info

Hot answers tagged

112

Because arrays teach concepts like indexing and bounds, two fundamentally important concepts in computer programming. Lists are not a "standard." Contrary to popular belief, there are still a wide variety of problem spaces for which arrays are a perfect fit.


45

They probably wanted to start with the data structure that most accurately represents how a computer works, so you're familiar with the fundamentals before they start introducing higher-level abstractions like Lists which make it easier to work with. Otherwise you'd have no way of understanding why a certain structure or algorithm is slow/fast for some ...


18

The answers above are great, but I have another in mind. Java's main() method means that students encounter basic arrays very early on, often as soon as the first day of class. Why? public static void main(String[] args) It's the first thing you're going to have to deal with to write Hello World and beyond. (I've seen some courses use teaching IDEs like ...


17

Ah, back when we had sticks and stones. Before the Internet, we had something called "client/server" architecture and Local Area Networks. If you weren't trying to establish a connection with a server several miles away, these networks worked perfectly fine to accomplish most anything. You could even establish drive letters and use connections to file ...


13

One reason that first-year programming classes use arrays is legacy: that's how the professors originally learned it before we started using standard libraries with dynamic lists baked in. Using the primitive data types is also more generally applicable: arrays exist in pretty much any computer language under the sun (and can be implemented in a handful of ...


13

I agree with you, and e.g. pylint would complain about those names too (albeit purely on a length basis). for k, v in ... gives the reader no helpful information about what they should be expecting to get from the dictionary, which makes the subsequent code harder to follow. For example, it's only at if v['tree']... that you find out that the value is ...


12

Where I work, the author of the code changes is responsible for testing that those changes actually work, while the code reviewer is typically responsible for finding any issues with the readability/maintainability of those changes or spotting corner cases the author might not have thought to test for. In general, the reviewer looks for the sort of problems ...


11

It's called a cache, the technique is called caching. A cache is something that stores data in order to speed up further requests for that same data. That data may be the result of some expensive computation and thus be cached to avoid repeating that costly computation. It might also be a copy of some data that is already pre-computed elsewhere but is ...


10

Depending on what you call a web service. Before WSDL and REST, there was still HTTP, so basically everything you can do now could be done before as well. There was a lack of uniformity (which is why WSDL and REST were created in the first place), but it provided the same level of data confidentiality and security you are talking about. You can actually ...


7

Some hardware cannot read non-aligned data. True. For example Bitmap images are aligned to 4-bytes from the header and with each scan line in order to maintain device independence. I have a number of points to make on this sentence: The internal organization of bitmap files is not an example of hardware being or not being able to read ...


7

Java allows variables of any type to be stored into arrays. By contrast, ArrayList only allows storage of references. One may thus not usefully discuss ArrayList without first covering how auto-boxing will convert primitives to reference types, and how auto-unboxing will sometimes convert reference types to primitives: for (int i=10; i<=10000; i*=10) { ...


6

I think it makes sense to teach how to use arrays first due to the fact that ArrayList uses an array internally. The ArrayList class has a member variable called elementData which is an Object array. From the JDK ArrayList source code: /** * The array buffer into which the elements of the ArrayList are stored. * The capacity of the ArrayList is the ...


6

You're not doing ternary logic, you're just using null as a placeholder for a missing value that happens to be of type Boolean. (Not having true nor false isn't quite the same as having one of the two but not knowing which.) Using null this way is a fairly common practice, but I wouldn't call it a good one. It's unlikely to cause you problems in this ...


5

I find it good practice to add a sentence or two to document the intended usage of the exception class. For example, the documentation of java.lang.ArrayIndexOutOfBoundesException states: Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array. Such a ...


4

is it really effective to review changes just by reading the code (...)? If you have enough practice coding you will be able to spot bugs without software/coding environment. It's good practice to read raw text and try to pick out the errors (logic or syntax). It will help you become a stronger programmer.


4

The input array that you have is: 0, 3, 3, 7, 5, 3, 11, 1 Imagine that the array instead would be this: 0, 1, 3, 3, 3, 5, 7, 11 If the array were organized like that, then you could loop through the array and more easily count pairs. 0 --> 1 1 --> 3, 3, 3 3 --> 3, 3, 5 3 --> 3, 5 3 --> 5 5 --> 7 7 --> 11 That's 1 + 3 + 3 + 2 + 1 ...


4

In our team, the style and general coding rules are checked by code analyzers with every build. Therefore when we review the code, mostly the code written by juniors, we try to spot the parts that does not follow the architecture and design patterns because these cannot be checked automatically by tools easily. We don't run the code because it is mandatory ...


4

Code review is mostly about the readability and maintainability of the code. You also have a sanity check on whether the changes relate in any way to the actual change request. If it confuses the code reviewer it will probably confuse any one who has to amend the code subsequently. Yes code reviews can pick up other potential bugs, but most of these could ...


3

Just to clear up some concepts first... I believe data access through a webservice provides security - I don't need to pass in the db server user name and password etc. I think you are conflating the concepts of (1) Transport Layer Security (TLS) and (2) access controls in the above statement... Whether a user name and password needs to be supplied or ...


3

You have to write a test that works independent of the config file, so you can test that depending on the "simulated configuration" the output of the function or behavior of that function is correct. You would need to inject the configuration file, or the value that you are trying to simulate on your function under test. This is the only way to guarantee ...


3

Remember me cookies are a special kind of cookie because they allow the user to bypass providing the authentication information, while other cookies may just track what pages you have been on or what is in your shopping cart as a non logged in (unauthenticated) user and aren't really risky except to the extent that such information is assumed to be private. ...


2

An HTML document consists of strings of text surrounded by pairs of markup tags, so...there isn't really any shortage of places to put a string. You could have an "HTML document" that's nothing but the string. You could have the usual head/body and a single div in the body whose content is the string. One of the divs could contain Lua source code for all we ...


2

While using null or using an Optional are reasonable choices, one more option would be to add an explicit second field, boolean _hasBeenRead. Your code would look like private boolean getValue() { if (_hasBeenRead) return _valueCache; else { // read the value and, if successful, set both _hasBeenRead and _valueCache. } } Some ...


2

Assuming that list are indeed easier to work with, as you say — that doesn't really matter. Learning is more about "basic to complex" than "easy to hard". If fundamentals weren't important, then computer science wouldn't be an academic field. You could just learn how to click together apps using existing frameworks/libraries from online tutorials. ...


2

It's because the most crucial thing in academic education is to teach you to use the correct terminology to describe the things you do. List is something other that array. and You can't use java.util.List in Java because it's an interface. You usually use java.util.ArrayList which being a List implementation, is not a list, but an object wrapper around ...


2

PEP 8 Allows you a bit of flexibility¸but requires consistency. I would use underscored caps, as per your initial suggestion for all constants, since what will make them instantly recognizable and distinct from Class names and other variables. So in short it is right. But when working on a project where a different patterns are follow the pattern used in ...


2

As usual: If you need to implement some methods, the interface is not a solution. You have to use an abstract class. On the other hand, if you need to describe the behavior, especially in a context where classes which have this behavior might already have a parent class, you have to use an interface, since in C#, a class cannot have multiple parents. If ...


2

I would argue if there is a piece of code you need to run or debug first to understand what it does, the code has to be improved in terms of readability, and the review which has revealed that was quite effective.


2

Automated testing Invest your time in automated testing. It will pay you off very quickly. The basic idea is that if you do manual testing only, you'll be unable to handle the ever increasing number of tests. It is not unusual for even a relatively small application to have thousands of tests, not counting integration, system, functional, load and other ...


1

I would say documenting knowledge is much more prone to change (especially if you have an urge to document it) than documenting intent. So documenting intent is more effective if comparing the two. Here is what I mean: When you are talking about how something is done it has two downsides: 1) It is not clear how you are doing something and so you are ...



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