Language agnostic What does it mean to "program to an interface"?

I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this? I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly. Is it just so if you were to do: IInterface classRef = new ObjectWhatever() You could use any class that implements IInterface? When would you need to do that? The only thing I can think of is if you have a method and you are unsure of what object will be passed ex

Language agnostic The "You're Doing It Wrong!!" feeling

NB - This question is not a stab at RoR or at Redmine's plugin system I have been working on a custom plugin for Redmine, a project manager platform built with Ruby on Rails (RoR). Now I am not really a RoR or for that matter, a Ruby guy. I have managed to write the plugin and everything works, despite being a mess behind the scenes. The "You're Doing It Wrong!!" feeling is coming from the fact that I know RoR is a highly-regarded framework, so there must be simple, better, elegant, [inser

Language agnostic Is design now a subset of refactoring?

Looking at the cool new principles of software development: Agile You Ain't Gonna Need It Less As A Competitive Advantage Behaviour-Driven Development The Evils Of Premature Optimization The New Way seems to be to dive in and write what you need to achieve the first iteration of scope objectives, and refactor as necessary to have elegant solutions. Your codebase grows incrementally, and never has a big planning/hierarchical design stage. That, to me, suggests that software design (worthy tho

Language agnostic How is web programming different from back-end programming?

I have worked on single threaded business logic/back-end programming for most of my career. I now wish to learn web programming but would like to know how web programming is different from non-GUI programming (e.g. writing an API or a file processing application). I am not talking about the GUI design aspects (someone has already asked that question here) but more about programming complexity. On the few occasions when I have worked on a web application, I felt that web applications are relativ

Language agnostic Entering imperial length measurements on a web form

I live in Australia and have not dealt much with imperial length measurements. How would you go about getting users to enter imperial length measurements on a web form, with a precision of 1/64th of an inch? I have thought of several ways to do it, but I don't know if there is a standard way of doing it, that users in the building industry in the USA would be used to. Option 1 One big text box that users would then type in 5'11" 63/64 (5 feet, 11.984375 inches), which I would then parse, and s

Language agnostic Benchmarking: When can I stop making measurements?

I have a series of functions that are all designed to do the same thing. The same inputs produce the same outputs, but the time that it takes to do them varies by function. I want to determine which one is 'fastest', and I want to have some confidence that my measurement is 'statistically significant'. Perusing Wikipedia and the interwebs tells me that statistical significance means that a measurement or group of measurements is different from a null hypothesis by a p-value threshold. How w

Language agnostic How should I be handling checksum collisions in my application?

I have a part of my application that stores files. Because we could potentially be adding many of the same file, I am first keeping a hash of each file. If two files have the same hash, then we throw out one, and both "references" to that file point to the same physical file. How much should I be worried about hash collisions? In the case of a collision what should I do? The whole crux of my code so far depends on there not being two different files with the same hash. In the event of a c

Language agnostic Function to determine number of unordered combinations with non-unqiue choices

I'm trying to determine the function for determining the number of unordered combinations with non-unique choices. Given: n = number of unique symbols to select from r = number of choices Example... for n=3, r=3, the result would be: (edit: added missing values pointed out by Dav) 000 001 002 011 012 022 111 112 122 222 I know the formula for permutations (unordered, unique selections), but I can't figure out how allowing repetition increases the set.

Language agnostic Mandatory method documentation

On my previous job, providing all methods with javadoc was mandatory, which resulted in things like: /** * Sets the Frobber. * * @param frobber The frobber */ public setFrobber(Frobber frobber) { ... } As you can see, the documentation takes up space and work, but adds little to the code. Should documenting all methods be mandatory or optional? Is there a rule for which methods to document? What are pros and cons of requiring every method to be documented?

Language agnostic How to work with this turing machine?

This is a screenshot of the applet LogiCell 1.0, link to which I found here. As the bottom left corner shows, this is doing sum 0+1 and the result is 01b (bottom right hand side). I am not able to link what is displayed to what the inputs ans outputs are. For example in this case - seeing the snapshot, how do you determine that the inputs are 0 and 1 and the output is 01?

Language agnostic Documenting getters and setters

For simple getters/setters, like the one below, what's the best way to document it? public float getPrice() { return price; } I'm pretty strict about coding standards, so my IDE warns me about any undocumented public/protected methods. Option 1: /** * Get the price field. * * @return */ Option 2: /** * @return Price */ Or don't document it at all?

Language agnostic When/why to use custom exceptions

I read a thread on this topic on this very forum which listed some reasons to use custom exceptions but none of them really seemed strong reasons (can't remember the reasons now). So why would you use custom exceptins? In particular, I have never understood the decision making process between using a standard or custom exception to indicate a shopping basket is null (I think a custom one is used as an empty collection is not exceptional and this is a business process thing). More clarification

Language agnostic How to make an escape the room game

I want to make a very simple "escape the room" game. I was hoping for something that looks something like this. You would see images of some room and you click around to move or to add things to inventory. Then, you can select something in your inventory to use that item with something on the screen. During the whole game there would be a text box describing what is happening (probably in really broken English instead of Japanese). I am looking for something that can be quite simple. I wou

Language agnostic Naming convention (or a term) for parameters that could represent either a collection or a single item

My particular case deals with Ruby, though it could apply to almost any language. I've been using noun_or_nouns to name parameters that could represent either a collection or a single item. For example: action_or_actions, favorite_sidewalk_or_sidewalks Is there a less awkward naming convention? Is there a single word to describe objects that could be a collection or a single item? I've mainly dealt with C++ and C#, and this sort of thing rarely comes up in either of those languages. I'm loo

Language agnostic Best way to handle multiple files adding/editing/deleting in web applications from ui point of view?

Application platform is WWW. I have user interface dilema. My user can have many files. File has attributes such as name and description that can be changed by user. Currently I have users list with edit action when I only allow to edit user data such as name, address, phone etc. on one screen, and files list with links to edit or delete for individual file on another screen. I think it would be nice to allow user to edit his data and adding/editing/deleting files on one screen, but assuming

Language agnostic Is there a name for the concept of a type such as this

I have a type that is constructed using information from various domain entities. The type itself is present because within some contexts in the system it is useful and meaningful to abstract away from the large and complex legacy types that supply the information for the type. It exposes a subset of the fields of the types used to instantiate it, plus it contains some functionality of its own. The type has its own service, providing a creation method, that under the hood, coordinates the cr

Language agnostic Bytes in a 32 bit system?

I am in the process of interviewing at a few places and I saw this question in one of the discussion forums. How many bytes are contained in a 32 bit system? The answer given is 2^29 or 536870912 - I believe it's because a 32 bit system can address 2^32 bits of memory and 8 bits to a byte gives 2^32/8 = 2^29 bytes. Can someone confirm if I'm on the right track? Thanks!

Language agnostic Convert a coordinate system into a board for a game

I currently have code that prints out a coordinate system as shown below. The code asks the user to input dimensions and then prints out a coordinate system appropriately. The board below is a 5 x 5. (0, 0) (1, 0) (2, 0) (3, 0) (4, 0) (0, 1) (1, 1) (2, 1) (3, 1) (4, 1) (0, 2) (1, 2) (2, 2) (3, 2) (4, 2) (0, 3) (1, 3) (2, 3) (3, 3) (4, 3) (0, 4) (1, 4) (2, 4) (3, 4) (4, 4) I was wondering if anyone could give me a hand as to how to convert this into a board that looks like this: X O

Language agnostic Story Map (Visualization of Requirements)

in our company we try to establish the concept of a Story Map (Jeff Patton ) at the moment. I have the following questions: - What happens in a story map with cross-cutting issues/tasks? We have activities that run throughout the project. How are these activities in a story map being held? In a story map, there are areas of responsibility. What happens when an activity is moved from one area of the map to another but the other activities remain unchanged in the time sequence. Are the task are

Language agnostic How do you communicate messages to a PLC

I have no experience with PLC's whatsoever, but for the next project that I will be doing, I will have to develop an application that will communicate with a PLC. Basically, I will get an XML-message which I have to forward to the PLC. I won't be doing the development of the PLC code, but I would like to understand how I can design the PLC data structures (resembling the xml schema as closely as possible) and send messages to the PLC. The programming language of the application is not yet chose

Language agnostic Methods for automated synonym detection

I am currently working on a neural network based approach to short document classification, and since the corpuses I am working with are usually around ten words, the standard statistical document classification methods are of limited use. Due to this fact I am attempting to implement some form of automated synonym detection for the matches provided in the training. My question more specifically is about resolving a situation as follows: Say I have classifications of "Involving Food", and one o

Language agnostic Comment wizardry

I am not a level 60 wizard yet, so I've got a question based on the following sentence in the Wikipedia article on magic: Any comment that has an effect on the code is magic. How is that? In what languages is such a thing possible? More specifically, what effect can a comment have on the code?

Language agnostic Dividing N points in a 2-D graph into 2 groups

Suppose there are N points in a 2-D graph.Each point has some weight attached to it.I am required to draw a straight line such a way that the line divides the points into 2 groups such that total weight(sum of weight of points in that group) of part with smaller weight be as many as possible.My task is to find this value.How to go about it ? Note:No three points lie on the same line. This is not a homework or part of any contest.

Language agnostic Can languages with char counts be described by context free grammars?

I am looking at a the German HBCI/FinTS protocol. One peculiarity of this protocol is that it can contain binary blobs, which are prefixed by @NUM_OF_BINARY_CHARS@. Otherwise the protocol is quite simple, a grammar could be described as follows (a bit simplified, terminals are quoted by "): message = segment+ segment = elements "'" elements = element "+" elements | element element = items items = item ":" items | item item = [a-zA-Z0-9,._-]* | escaped item escaped = ?[-@?_-a-zA-Z0-9,

Language agnostic Given a GUID, if i shorten it .. can we assume it will still be unique?

Given that GUID's are (more or less) unique, if we shorten it with some code which: It basically just converts a GUID into a base64 string and shortens it a bit. It takes a standard GUID like this: c9a646d3-9c61-4cb7-bfcd-ee2522c8f633 And converts it into this smaller string: 00amyWGct0y_ze4lIsj2Mw Can I now assume that the shortened guid is equally as unique as it's previous (normal) form?

Language agnostic What operations must be implemented for the List Abstract Data Type

I understand what an Abstract Data Type (ADT), and how Concrete Data Types are used to implement them. How do languages like Java decide what methods they need to implement for the List ADT when designing an Array List for example. Are there a set number of operations for the List Abstract Data Type that any language must implement and does it matter what the language calls them?

Language agnostic Object Normalization

In the same line as Database Normalization - is there an approach to object normalization, not design pattern, but the same mathematical like approach to normalizing object creation. For example: first normal form: no repeating fields.... here's some links to DB Normalization: Would this make object creation and self-documentation better? Here's a link to a book about

Language agnostic Is it a good idea to eliminate compiler warnings?

In the past I've worked with -Wall and other switches for gcc to eliminate every compiler warning for projects I've been involved in. Similarly, in Perl, I always program with use strict and use warnings (and often -T as well) to try to achieve the best code quality I can. I understand that a few years ago, the Perl porters group worked hard to make perl itself (the Perl interpreter) compile cleanly under gcc with all warnings enabled. Obviously they felt that was a good idea for code quality.

Language agnostic What is the best way to replace or substitute if..else if..else trees in programs?

This question is motivated by something I've lately started to see a bit too often, the if..else if..else structure. While it's simple and has its uses, something about it keeps telling me again and again that it could be substituted with something that's more fine-grained, elegant and just generally easier to keep up-to-date. To be as specific as possible, this is what I mean: if (i == 1) { doOne(); } else if (i == 2) { doTwo(); } else if (i == 3) { doThree(); } else { doNone(

Language agnostic When does it make sense to return this-reference?

Currently I can think of only three good reasons to return this in a (public) method, namely: (mmyers) when implementing fluent interfaces, e.g. public class X { ... public X enableValidation() { setValidation(true); return this; } ... } (Jon Skeet) for identity conversions, e.g. public class X { ... public X toX() { return this; } ... } (Dave Ray) implementing a clone() or copy() method on an immutable object, e.g. @Immutable public class X { ... publi

Language agnostic Function Parameter best practice

I have question regarding the use of function parameters. In the past I have always written my code such that all information needed by a function is passed in as a parameter. I.e. global parameters are not used. However through looking over other peoples code, functions without parameters seem to be the norm. I should note that these are for private functions of a class and that the values that would have been passed in as paramaters are in fact private member variables for that class. This

Language agnostic Optional vs. mandatory terminators in context-free grammar definition

In a book chapter about compilers, there's the following grammar definition and example code. ... statement: whileStatement | ifStatement | ... // Other statement possibilities | '{' statementSequence '}' whileStatement: 'while' '(' expression ')' statement ifStatement: ... // Definition of "if" statementSequence: '' // empty sequence (null) | statement ';' statementSequence expression: ... // Definition of "expression" ... // More

Language agnostic How, in general, can web framework support REST style?

I would like to know, what are the ways a web framework may be suitable for designing a RESTful app, in general. One goal is for example to provide http request routing, so they are automatically sent to appropriate controllers. From architectural point of view, web framework based on MVC pattern are more suitable for REST. What other features of web frameworks are helpful by building apps satisfying the REST constraints? Is there any reason why you consider certain languages(python/java) or

Language agnostic Should I subclass or use enum?

I have many T arrays to read. Each T array can represent data of type A, B or C. A: A list of T B: A single T C: Exactly three T When I read a T array, I will be able to get a list of T, and determine by reading the first T in the list whether it's of type A, B or C. I thought of two possible approaches and would like to know their merits and cons. 1) enum {A, B, C}; class X { enum dataType;//A, B or C List<T> data;//just store all as list of T //other essential methods/pro

Language agnostic What is a good heuristic for determining the tab width used in a source file?

I would like to determine the tab width used in source files indented with spaces. This is not hard for files with particularly regular indentation, where the leading spaces are only used for indentation, always in multiples of the tab width, and with indentation increasing one level at at time. But many files will have some departure from this sort of regular indentation, generally for some form of vertical alignment. I'm thus looking for a good heuristic to estimate what tab width was used, a

Language agnostic Advantages of Weak Typing over Strong Typing

So, I've read a bunch of similar questions on Stack Overflow regarding this issue, and I think I have a good grasp of what the differences between the two are. My question is whether there is any advantage of weak typing over strong typing beyond the fact that some operations are simply easier for programmers. While I agree that some operations between types are unnecessarily complicated by strongly typed languages, it seems like everything that a weakly typed language can still be done in a s

Language agnostic touchscreen: distinguish start of scroll from tap

I'm writing something for a touchscreen phone. I'd like the program to run a specified function when the user taps on the screen. I'd like to scroll the screen when the user drags a finger up or down the screen. The OS has three relevant callback functions (1) detect when screen is touched, (2) detect when finger is dragged on screen and (3) detect when the finger leaves the screen. In each case, the callback function gets the screen coordinates where the relevant event happened. The problem

Language agnostic Data types where precision level means range of tolerance

What existing terminology and art is there for data types that have values implying ranges of tolerance, not specific points? An example: time values. In ISO 8601 notation, the value 1964 encompasses the values 1964-05, 1964-05-02, 1964-05-02T18, 1964-05-02T18:27, 1964-05-02T18:27:43, 1964-05-02T18:27:43.0613. That is, each one of those values is not a zero-dimensional point, but an interval encompassing a range of more-precise values. The more precise values in that set should compare equal

Language agnostic What are the actual advantages of the visitor pattern? What are the alternatives?

I read quite a lot about the visitor pattern and its supposed advantages. To me however it seems they are not that much advantages when applied in practice: "Convenient" and "elegant" seems to mean lots and lots of boilerplate code Therefore, the code is hard to follow. Also 'accept'/'visit' is not very descriptive Even uglier boilerplate code if your programming language has no method overloading (i.e. Vala) You cannot in general add new operations to an existing type hierarchy without modifi

  1    2   3   4   5   6  ... 下一页 最后一页 共 16 页