instruction
stringlengths
34
19.9k
My question is about pointers in C. As far as I've learned and searched, pointers can only store addresses of other variables, but cannot store the actual values (like integers or characters). But in the code below the char pointer c actually storing a string. It executes without errors and give the output as 'name'. #...
I'm writing this very simple program from this one PDF called Think AP Java, and I can't seem to wrap my head around this: When I write public static double method_1(double x) { double result =( x*(Math.exp(-x) ) ) + (Math.sqrt(1-Math.exp(-x) ) ); System.out.println(result); return result; ...
We are writing a search engine from scratch in a quite uncommon language, Aramaic, mostly for learning purposes but also because few resources are available in given language. The engine is/will be written in Python, and: It is a human language search engine. It's not about paying someone to do the tests, but tryin...
I have a colleague sitting next to me who designed an interface like this: public interface IEventGetter { public List<FooType> getFooList(String fooName, Date start, Date end) throws Exception; .... } The problem is, right now, we are not using this "end" parameter anywhere in our code, it's just th...
I would like to implement a robust way to handle ecommerce payment for items with limited quantity, like for example exclusive paintings. Payment would ideally be accepted via PayPal and credit cards. Ideally, it would work on a 'first-come-first-serve' basis, and wouldn't just lock items out if you add them to cart ...
[If this fits more to stackoverflow then transfer it there please.] Hi, I'm trying to implement a priority queue in C. The easiest way I found to do it is with a circular array (rather than using a linked list). I have an array of fixed size, the index for the first element in the queue and the index for the next free ...
Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] single-method interfaces? Is there an objective rule against this? Not something like "oh it feels wrong" or "but you will...
I plan to write a website frontend for a free computer algebra system (Reduce, http://reduce-algebra.com/). On the webserver I have a Java virtual machine running, and Reduce is also installed. I can start the application via exec() in the Java file. But my question is the following: how can I emulate user inputs and h...
When I evaluate asp.net control events, I am not able to identify how the browser is aware of asp.net textbox is subscribed to serverside textchanged event or not. When I look the server generated HTML code, there is not information about the TextChanged event. ASP.Net Declaration <asp:TextBox ID="txtInput" runat="serv...
We are starting rewritting our apps (Internet portal, millions of unique users and few CRM/ERP systems, few hundred users) and we have a huge decision to make now. We are going to write them mostly (90-95%) in Symfony2 with Doctrine, and some background services (e.g. mailing) in Java. Database - MySql/MariaDb. also lo...
I have always kept the code to load an object within the object itself. That way no matter what method is creating the object, it always has access to the method to load the object. However this does mean that if I'm loading a lot of objects I have to create a blank copy of an object to retrieve an array of objects, an...
I'm looking for an algorithm idea on how to traverse a matrix using a linear index while avoiding row/column based traversals to get a more diverse distribution of values. To understand this better, think of an image that's split in blocks, with N rows & M columns. I need to process each image block sequentially (from ...
I have a list of sounds that are to be played when the user presses a button. For now I just generate a random number within the range of the list and just pick the sound with that index. (I also prevent that sound from being played the next time the button is clicked. Since that is easy, I would like to concentrate on...
I work for an insurance company and we're getting ready to use a new vendor tool for creating insurance illustrations. The tool has a web service that accepts an ACORD XML message. We want to put a web service in front of the vendor web service to abstract it away, but the complexity of the data model makes it hard. Ou...
I'm in the elections division of my county and am trying to simplify a voter lookup method for our poll judges during election time. Currently we are using a clunky heavy application that the judges must install, and we only support Windows. My goal is to have an offline (client-side) browser based solution that will w...
Abstract I have been trying to get my head around the cohesiveness of some functionality in our code base. I’ve approached this design in different ways, and lately I’m convinced that I took the wrong approach, as in I incorrectly applied the Single Responsibility Principle. Issue The problem domain is a Well, othe...
How could a true Vector type be implemented in Haskell? In order for something to be a Vector, it has to be stored sequentially in memory, with O(1) random access. But Haskell hides its memory management, and its datatypes describe trees! So how could you express that kind of requirement?
I keep seeing the following pattern when people learn about OOP: Problem: How do I put objects of different but related types into a container? Solution: Inherit from a common base class. New problem: I have a bunch of base class objects, how do I get the real type? Solution: ??? The classic inheritance example is to m...
In the comments to this former question, there was a discussion if the C standard allows variable length arrays (VLAs) of length 0 or not. As it turns out, the C99 standard states: In 6.7.5.2 Array declarators, Constraints: "If the expression [for the array size] is a constant expression, it shall have a value greater...
I was wondering what is the exact difference between a client-server and a standalone application, particularly in following scenario. For example lets say there is a win forms application running on a PC. So that the DBMS, SQL Server also installed on the same PC as it hosts the database too. Now this is clearly a sta...
Lately I've been playing with CSS (and other web technologies). I'm a non-web programmer, and probably this is influencing way too much my approach. I found CSS syntax very limited, thus gave a shot to SASS and LESS (mostly the latter). These two languages are a lot more handy, but I'm still getting into several issues...
I've only worked on client side(specifically, mobile) applications using Android, where all networking is handled at the HTTP layer using framework provided components like HttpUrlConnection. But push messaging systems like Websockets/XMPP etc, all maintain a persistent connection to the server. Even Google's GCM, whic...
I originally started out this question with "what is jQuery, and how does it work", in terms of all that fancy animation, effects, slideshow plugins, etc. I was uncertain as to how JQuery does all that fancy stuff. But after reading around on the internet, I am happy to acknowledge that jQuery is basically a "JavaScrip...
I have a working Ruby on Rails Model that I suspect is inefficient, hard to maintain, and full of unnecessary SQL join queries. I want to optimize and refactor this Model (Quiz.rb) to comply with Rails best practices, but I'm not sure how I should do it. The Rails app is a game that has Missions with many Stages. Users...
I'm developing an application to keep some of the data in chronic patients, the data came from a very strict subset of data, vital signs, exams, ecc. On a first glance I thought to create a Patient model with has_many encounters, and put every info in a different field like (age, height, weight, ecc), but it will resul...
I want to build a similar notification mechanism that Facebook handles. I actually store the user's notification in an SQL table (actually it's a graph database but everybody master RDBMS terms). I'm interested in the case where the user clicks on the icon: The counter should get a value of 0 internally and visually ...
I'm watching a C++ tutorial video. It is talking about variables inside classes and assert that variables should be marked private. It explains that if I want to use them publicly, I should do it indirectly through functions. Why? What's the difference? It looks like the result is the same, except that instead of havin...
I'm a CS alumni, but we didn't learn much by the way of OOP, or Design Patterns. I've heard the phrase C with iostreams and thought it fitting. Anyway that's besides the point. I am just curious about what I perceive would be a very simple design pattern. Have any of you played the game Starcraft? You know how you can ...
I have a shared hosting with limited capabilities. Memcache and mod_cache are not available to me. I would like to implement my own PHP caching method to cache the results of load-intensive SQL query. Using summary tables in SQL is not an option because the query takes multiple parameters that can assume thousands of d...
I'm developing a library for reading/writing a file format of a program created by a certain company. The guys from that company were so kind that they provided me with a documentation for their format, which I'm really grateful for. I'm intending to release the library as open-source under a license "derived" from MIT...
In the design phase we create UML Sequence diagrams (in OOD). My understanding is that after creating an Use Case diagram if we need to show further information in terms of time sequence of events of that Use Case, we can go for sequence diagrams. My question is, should a sequence diagram represent exact implementatio...
I have a small game that I would like to keep track og global hiscores for. The basic is simple: username and score is submitted to a server for storage and later polling. However how do I ensure that these scores aren't faked? Obviously, just accepting a submitted user+score blindly will allow people to telnet in thei...
I'm reading this series on Laravel, and it's in great depth dealing with making everything testable, using Repository instead of just using the Models, using Dependency Injection and other obscure techniques. I've got a feeling that adding all this extra complexity in the name of Testability may not be the right thing....
When writing constructors, I regularly encounter a situation where some fields already have approperiate (default) values, such as false for boolean values and 0 for integers. What are reasons to emphasize these values, for example like: state = 0; Do you appreciate it when reading someones code? On one side I feel lik...
When compiling with Visual Studio C++, I noticed that you need a specific MSV C++ Redist, depending on the version of Visual Studio you compile with. The required redistributable is necessary on machines without it. Otherwise without the redists missing MSVCPxxx.dll errors are prompt. Is there a way to by-pass needing ...
I'm currently building a very small website, around 20 to 30 views, 10 controllers. I know MVC is only a design pattern and should only be the top presentation layer. I'm currently at a stage in development when you start question yourself and what you're doing. It feels like this small website don't 'need' the N-tier ...
I am working on an application using sockets. Essentially I want to stream data between two clients. Since I can't connect the two clients together directly (they aren't on the same network), I will need to connect the two through a server. My client-side is written in Java but the server-side could be written in any ...
I am learning about the MVP (Model-View-Presenter) Passive View flavour of MVC. I intend to expose events from view interfaces rather than using the observer pattern to remove explicit coupling with presenter. Context: Windows Forms / Client-Side JavaScript. I am led to believe that the MVP (or indeed MVC in general) p...
This macro can be defined in some global header, or better, as a compiler command line parameter: #define me (*this) And some usage example: some_header.h: inline void Update() { /* ... */ } main.cpp: #include "some_header.h" class A { public: void SetX(int x) { me.x = x; me.Update(); ...
I'm trying to store content scraped from several lyric and chord websites into separate variables into either a multi-dimensional array, or into separate string arrays, but I've been stuck trying some different approaches. I've searched through the site and have found many questions that were similar, though incompatib...
Where does binary go in a computer? When you turn the computer on it points to the bios and runs through it. I get that. Then it loads data off something ( disk, flash, etc. ). But where does it go? Does the binary go in ram? Does that mean if my program is 2mb and ram is 32mb I can only address 30mb? I mainly want to ...
I am building a strategy game where multiple units(5 - 20) fighting each other. I have a game logic that calculate all the actions that been done on each turn, and send it to the game engine to animate. Those are the possible actions: perform attack perform taking damage perform moving perform missing perform removing...
I have a number of controllers that take a 'site' as a parameter within their actions, like so: [AuthoriseSite] public ActionResult Index(string site) { var model = gvmFactory.CreateAnIndexViewModel(site); return View("Index", model); } I have been passing the site as a parameter but I could also calculate it...
When working on multiple similar projects there are often changes that can't be extracted into a library, but should be applied to most of the projects. I mean changes like a modified directory structure, some common configuration, similar ui code, etc. The most basic strategy is to copy a new project from the last fin...
I am authoring a lot of plugins for the content management system that I am writing. I believe it to be of utmost importance that script files (especially if they're plugins) should load quickly, which leads to me to the question that I've asked today? What's more important for plugins, minimizability or readability? L...
This seems like a basic question, but I have not found a definitive source. I need to modify the source for an LGPL application for my employer to plug a security hole. Longer term we will upgrade to a later version of this application, but for now, this is the quickest solution. (specifically: I will change a 2005-er...
I have given message encoded with non-optimal Huffman code. I need to decode the message and encode it again, but this time with optimal Huffman code, so after that I can find average_number_of_bits_per_symbols = num_of_bits_in_message / num_of_characters_in_message Example: input: 6 A 11 B 10 C 01 D 0001 E 001 F 0000...
I'm trying to think up a scenario when I'd have three different forms of NSData (or whatever) to be sent to three different services like Evernote, Google drive, Dropbox. Granted, each of those has there own SDKs to be bundled into the iOS app, and thats okay. Now, I want to create a single Class that serialises the b...
I am having trouble evaluating an implementation of the builder pattern I just came up with. The context is an API library, so I am trying not to expose any implementations in order to have a stable interface while being able to change implementations later. My thinking is that even though there is a reference to the i...
Is it ok to have subclass which does not declare its own variables (instance variables) and inherits from super class or base class? It has methods and there are some common methods which it overides but do not have variables of its own. Is it ok to have subclasses which defines behavior only or I am missing something?...
Suppose I have a MyList class which extends ObservableCollection<MyObject> where MyObject has the Boolean Property Enabled. Let's say I want the number of MyObject objects that have the Property Enabled equal to true. Should define this as a Property or a Method? In MyList class, should I use: public int GetNumEnabledM...
I have a select dropdown, with '+' and '-' buttons that add and remove items before submission. I would like to be able to remove the elements with the '-' button after they have been added to the database. I'm not sure how to go about doing this, other than removing prior entries and rewriting the options again. Ide...
One of the difficulties I'm running into with my current project is that the previous developer spaghetti'd the javascript code in lots of different files. We have modal dialogs that are reused in different places and I find that the same .js file is often loaded twice. My thinking is that I'd like to just load all of...
Using .NET - I have an interface IPerson. This interface is implemented by classes in multiple, separate repositories, e.g. EF6 (EfPerson), custom SQL (SqlPerson), or even custom assembly connecting to a web service (WebPerson). Assuming rich domain model, my idea is that my lovely rich domain object 'Person' could h...
I want to include a GPL & Apache duel-licensed font in my LGPL project, but didn't really find a clue if that's possible. There are two problems here: I didn't find any clue about Apache license's "LGPL Compatibilty". I know both the licenses involved here are compatible with GPL, but I still prefer to release the wor...
I have recently been told that using size_t as declared in the global namespace is incorrect in C++, ostensibly because size_t is a C-feature. I looked this up and came across this question on Stack Overflow: https://stackoverflow.com/questions/5813700/difference-between-size-t-and-stdsize-t The top answer makes it pre...
I'm working on a lawsuit and I need a definition of a 'class library' that I can reference. Every book and all the documentation I can find seems to assume the reader already knows what a library is. Even the wikipedia entry on 'Library (computing)' is low on references. And the references it does have are from the 80s...
I realize my precursory understanding on Monads is severely lacking in detail considering my knowledge comes mostly from Douglas Crockford's Monads and Gonads talk and complicated with my sevear handicap with Haskell (which looks like a bunch of non-alpha numeric characters mushed between disjointed English words to my...
I'd like to add a couple of command-line arguments to my Django's ./manage.py dbshell command, and I can't figure out how. In specific I'd like to add -A to prevent MySQL from scanning every table and every column, and --prompt=LOCAL: since I frequently keep multiple shells open. I can't figure out how to do this! I'm ...
I'm a beginner web developer (one year of experience). A couple of weeks after graduating, I got offered a job to build a web application for a company whose owner is not much of a tech guy. He recruited me to avoid theft of his idea, the high cost of development charged by a service company, and to have someone young ...
Question: Is there any standard model or industry defacto implementation for modeling and implementing Access Control in (i.e.) a Document Management System? Note: I studied a bit the security mechanism of Windows (which I do not want to use), and I saw Users and Groups and Policies. But I can't understand: 1 - How a...
I have a web-app that provides data (that is updated on an interval) for intranet users, who are able to filter information by location. I was having a discussion with a co-worker about whether that filtering should take place on the client vs server side. The amount of information isn't large, but the users are typica...
I'm thinking about creating my own pet programming language, and I have been wondering if similar language already exists. The basic idea is that the language itself would be dynamically typed with strong metaprogramming capabilities (think Ruby). But instead of running it directly, it would be interpreted/expanded int...
Perhaps I should have picked a better title, but anyway... Basically what to do with two or more implementations that have the same public interface, but they are meant for slightly different purposes having a slightly different behavior? For example let's say a proxy class that uses the same public interface of the or...
How a computer can be used when there is no operating system? What tools or knowledge do I need to do it? Do I have to give all the commands in binary to use computer hardware resources like a monitor?
I have a service written on .NET working on a company server. It designed to do a very simple thing, to receive a request via WCF named pipes from another service working locally on the same server, process it and send a response through named pipes back. Request an response are just a fairly small, XML formatted text....
I have a polyline "class" in my Clojure program, which is represented by a vector of points. (It's not really a class or anything.) The polyline's length (in the geometric sense) is something that is often needed for computations. It's also fairly slow to calculate every time it's needed. In OO code, I'd just have the ...
OOP is often regarded as an effective strategy of managing complexity in software, as opposed to non-OOP procedural programming. Have there been any studies testing this notion? Is it proven that OOP often helps manage complexity in large projects?
This is in context of a client-server architecture, although I don't think the architectural setting is needed to put up the problem. I have a function whose output can be classified into different categories: function makeCar() { /* make a car */ } Now, in order to decide the structure for the return value of makeCar...
I found a bug on my XFCE and some other can't repeat the bug, namely https://askubuntu.com/questions/495947/a-logo-disappear-in-xubuntu . How should I report it to the developers if those can't repeat is as well?
For every a and b which are non-const pointers of the same type, you can do a = b;, right? Inside non-const member functions the this keyword exists, which is a non-const pointer. So logicaly if b is same type as this you can also do this = b; right? Wrong. You cannot do this = b;, because this uses pointer syntax bu...
I'm in the process of designing an API, part of which involves writing POCOs to a database. In C#, we have the DateTime structure. The "default" value for this (DateTime.MinValue) is 01/01/0001. Part of the API serializes POCOs to the database. If a date field is optional, it should really be nullable (in C# syntax, ...
AngularJS and other web frameworks provide data binding abilities (as in WPF). Is the UI bound to JavaScript variables on the frontend (web browser) or is it bound to the data in the server (via AJAX and such)? I assumed that with all the MVC frameworks for the web, the model is the data on the server, the view is the...
One of the jar files that I use in my code is not in the maven repository(and yes I tried to avoid using it). I have installed it locally so when I build the project it gets picked up by maven. I also put instructions in my README so anyone who wants to build my code can see how to add the jar to their local repository...
Suppose I have distinct classes that have the same behavior, which can be represented like this: public interface Behavior { void operationA(); } public class ImplementerA implements Behavior { public void operationA() { } } public class ImplementerB implements Behavior { public void operationA() { ...
I'm using a charts-Plugin (Morris.js) in my AngularJS application. I'm building a directive for each type of chart. The plugin is called like this: new Morris.Line({ // ID of the element in which to draw the chart. element: 'myfirstchart', // Chart data records -- each entry in this array corresponds to a point o...
I am trying to create a basic licensing system where I take a unique ID from the client computer, and I get this Hexadecimal string (hyphens removed e.g. "84-18-CE-...."): "8418CFEE73FA22E6AB0760C73A496497C6C347DA88A9F63B95FE1E1D6A350AA1D7D3A9EE870795AECC3C109AA8B4A78C" It's only encoded into this format to make the...
I have a rather complex method which can get called in two possible "scenarios". One is a special case of the other in which all the nested foreach loops are only executed once and several if statements are false such that essentially only two lines of code nested deeply inside the method are actually executed. Now the...
I am working on a software integrated with the hardware component. I need to create a simple diagram to express that: Certain activity runs in a cycle (the device continously monitor a temperature) When the temperature deviates from the baseline and remains so for 10 seconds, a function is called I am writing a hig...
Given a base class with around 25 or so subclasses, I have found that adding an argument to the base constructor is painful. protected AbstractController(Service1 s1, Service2 s2, Service3 s3){ ... } public Concrete1Controller(Service1 s1, Service2 s2, Service3 s3) : base(s1, s2, s3) public Concrete2Controller(Service1...
I am kind of new in agile environment since I always participated in projects before which was only said to be agile while it wasn't. Now I am really in an agile project and I see a setback - if it is setback - of agile methodology, the lack of pre-planning. I see that our BA talks to key users, collects data, which ...
Related to: Is onError handler better than exceptions? Premise I am writing a piece of library code that performs certain tasks, to separate concerns, we decided it should not write to a log or write to the display directly, but instead provide an event registration mechanism that allows interested client code to liste...
One of the incidental complexities of introducing features to an existing system is that the programmer often has to touch several areas of code that are not immediately adjacent. Over the long haul it can be unclear when looking at a bit of code that it pertains to another bit found elsewhere. It's both ugly design ...
Specifically for a game programmer. If you really needed some assembly routines you could look for help, whereas back in the 80s/90s it was one of the mainstream languages. I read that compilers can generally equal (or beat) most hand written assembly code, so unless you are an embedded programmer who can only program ...
I've searched around and can't find anything on what the middle bytes of a >16-bit integer are called, if anything. Are there standard names for these bytes? E.g. the number 0x0D0C0B0A would have: MSB ??? ??? LSB 0D 0C 0B 0A
Being a junior developer in need of some money for new hardware, I have stumbled upon many of the freelancing websites, and really soon, I have gotten my first customer. Complete Project Management, CRM and simple accounting website for small business. As we have been discussing the terms, I have proposed GAE/Python/Bo...
A few years back, I wrote this answer to a question from which the following idea emerged. I call these "Type Descriptors", as I have never been able to find this pattern documented or formally described anywhere - not to be confused with type descriptors in C#, but it's the most accurate name I've been able to come up...
I am working on a project that generates technical brochures in batch. The 3rd party API that is being used expects POCOs with property names that match field names used in each of the brochure templates. The task I am seeking advice on is with the data source that will be used to populate these POCOs. The data is base...
There's a question that might be deemed a duplicate of this one (I use an IDE (Eclipse) to develop software. Why should I switch to vim or emacs?) but I don't think answers my question. I usually program in C++ (not exactly to create GUIs so rather low-level) and I find myself comfortable with editing code into visual...
I have just begun to learn Django/Python/Web Development. This problem has been troubling me for a while now. I am creating an application with multiple templates in Django. I have a views.py which is basically just rendering the responses to the respective templates and I have a models.py where I have structured my ...
I have seen a lot of posts recently saying that one of the major reasons why Agile is used is because clients often change the requirements. However, let's say the clients do not change the requirements often. In fact, the clients have firm requirements though might be a bit vague (but nothing unreasonably vague), but ...
Since I last had to do any comms/network programming, the field has exploded with acronyms. In fact, networking almost feels like it is now described by a whole new language. The very name "Windows Communication Foundation" suggests it should be all things to all people... but I need to be sure I can program up some sy...
I have been arguying with a developer who insists that 1 functional request (FR) == 1 use case (UC). I think that is nonsense as there are requirements often describing situations arising from the same point - for this the use cases have alternate flows. For example: FR01 - User can log in FR02 - User's account will be...
How are objects organized in memory? For instance, I know that a function is a piece of code in memory, that expects parameters via the stack and/or the registers and handles it's own stack frame. But objects are a much more complicated structure. How are they organized? Does each object have "links" to methods and ...
I work in a team of people with experience in varied programming languages. Recently we were required to build a report when an order is placed in our system. Our ecommerce store runs on PHP and the program to send the report was written in Java. The major challenge we faced was setting up a way so that the Java proces...
A run a simple test JDK 1.7.0_45 (Windows 7, 64bit): Test 1: long start = System.nanoTime(); for (int i=0; i < 1000000; i++) { System.currentTimeMillis(); } elapsed = System.nanoTime() - start; Versus Test 2: long start = System.nanoTime(); long adjust = 313231; for (int i=0; i < 1000000; i++) { long result =...
I'm learning DDD and yet I have more questions than answers. Let's consider a model of a directory containing enormous number of files. Here is how I see it: Directory is an Aggregate root. This entity should have the validation logic of checking file name uniqueness when it is added or just renamed. And File entity c...
When writing object-oriented code from scratch, I try to follow these steps: Write a test that fails. Write a function that makes the test pass. When enough tests and functions are complete, refactor functions with similar signature into a class. When the class functionality is complete, make private as many of the cl...
Good day. I have been told that a good practice for writing methods is to make the method only responsible for doing one thing. It made sense to me now that I look back upon it in retrospect. There are a couple of reasons I like coding in such a way - to me they are: Code is Manageable Code is more human readable Bett...
I need a simple pathfinding algorithmn to go from point A to point B. A* seems like an overkill because It doesn't matter wheather I hit walls or not and there's no terrain. I was wondering if there was a simpler one which would find a direct path(a straight line) from point A to B.