Tag Info

New answers tagged

0

You are simply lacking something called ORM - either via a Framework or (only in some use cases recommended) handcrafted. Via ORM you define the Entity Relationships via code (e.g. 1 Order <-> n OrderPositions). And if you are using a framework the magic begins: you are able to resolve in one coded query all/most relationships which are needed - Little ...


0

So by the sounds of it you have an anemic domain model http://www.martinfowler.com/bliki/AnemicDomainModel.html This is a problem because you have objects that aren't actually doing anything other than holding data, but you have all the overhead of classes and objects without any behaviour. If you can't figure out what your objects are doing other than ...


1

How much space would this count take? 10 bytes? Unless you're trying to compress your payload to an absolute minimum, I would do calculations on a server, and keep logic that can be executed on a server on a server. Makes it a bit easier to maintain, less strain on client devices if it matters, etc.


1

Isn't this what HashTables are for ? If all you want to do is keep records of which resources have been used in the past months and delete resources that haven't been accessed in the last 18 months then you can use a HashTable where the Key is the resource_id and the value is the last access date. For archiving the >18 months records you can go through all ...


4

As you figured out by yourself, SQL is the way to go, but if you put the SQL commands into scripts or embed them in code does actually not make a big difference. What matters is that you make the upgrade process robust. Therefore, I would recommend to consider the following improvement over track your changes in sequential sql or code files Instead, ...


7

SQL scripts are the right way to go: The information was originally created via a sql statements, most reliable repeat-ability would come from the same script Import/export can also get tricky if two devs are modifying the same table. It's hard to code review an export file. It's hard to debug an export file We have 5 database environments in our world: ...


3

Most processors provide different instructions for working with data of different types, so type information is usually "baked in" to the generated machine code. There's no need to store additional type metadata. Some concrete examples might help. The machine code below was generated using gcc 4.1.2 on an x86_64 system running SuSE Linux Enterprise ...


2

Ok, so here's what I came up with. This contains Java, better get yourself some coffee. The Irish one. (for the same reason) In a sense, a tree is self similar. After all, a tree is a graph. Each node knows a certain number of other nodes. Speaking of Nodes: import java.util.HashMap; public class Node <Child extends ICanBeMergedWith<? super ...


0

Short answer, the type is encoded in the CPU instructions the compiler generates. Although the information about the type or size of the information is not directly stored, the compiler does keep track of this information when accessing, modifying and storing values in these variables. how does the execution know that a is a char and x is an int? It ...


1

You have to distinguish between compiletime and runtime on the one hand and code and data on the other hand. From a machine perspective it is no difference between what you call code or instructions and what you call data. It all comes down to numbers. But some sequences - what we would call code - do something what we find usefull, others would simply ...


-4

The other answers are correct in that essentially every consumer device you will encounter doesn't store type information. However, there have been several hardware designs in the past (and the present day, in a research context) that use a tagged architecture -- they store both the data and the type (and possibly other information as well). These would most ...


5

Historically, C regarded memory as consisting of a number of groups of numbered slots of type unsigned char (also called "byte", though it need not always be 8 bits). Any code which used anything stored in memory would need to know which slot or slots the information was stored in, and know what should be done with the information there [e.g. "interpret the ...


1

My answer here is somewhat simplified and will refer only to C. No, type information does not get stored in the program. int or char are not type indicators to the CPU; only to the compiler. The exe created by the compiler will have instructions to manipulate ints if the variable was declared as an int. Likewise, if the variable was declared as a char, ...


0

At the lowest level, in the actual physical CPU there are no types at all (ignoring the floating point units). Just patterns of bits. A computer works by manipulating patterns of bits, very, very fast. That's all the CPU ever does, all it ever can do. There's no such thing as an int, or a char. x = 4 + 5 Will execute as: Load 00000100 into register 1 ...


2

Let us keep this discussion to the C language only. The program you are referring to is written in a high level language like C. The computer understand machine language only. Higher level languages gives the programmer the ability to express logic in a more human friendly way which is then translated into machine code which the microprocessor can decode ...


34

I think your main question seems to be: "If the type is erased at compile-time and not retained at runtime, then how does the computer know whether to execute code wich interprets it as an int or to execute code which interprets it as a char?" And the answer is … the computer doesn't. However, the compiler does know, and it will have simply put the correct ...


8

The computer doesn't "know" what addresses are what, but the knowledge of what's what is baked into the instructions of your program. When you write a C program that writes and reads a char variable, the compiler creates assembly code that writes that piece of data somewhere as a char, and there is some other code somewhere else that reads a memory address ...


101

To address the question you've posted in several comments(which I think you should edit into your post): What I don't understand is how does the computer know lets when it reads a variable's value from and address such as 10001 if is an int or char. Imagine I click on a program called anyprog.exe. Immediately the code starts executing. Does this exe file ...


7

It doesn't. Once C is compiled to machine code, the machine just sees a bunch of bits. How those bits are interpreted depends on what operations are being performed on them as opposed to some additional metadata. The types you enter in your source code are just for the compiler. It takes what type you say the data is supposed to be and, to the best of its ...


3

In C, it is not. Other languages (e.g., Lisp, Python) have dynamic types but C is statically-typed. That means that your program must know what type the data is to properly interpret is as a character, an integer, etc. Usually the compiler takes care of this for you, and if you do something wrong, you'll get a compile-time error (or warning).


0

Did you consider using some JSON-based noSQL database like MongoDB? It might perhaps fit your needs. And you obviously can put JSON text in some SQL relational database like PostgreSQL, MariaDB (or MySQL) or Sqlite Saving your persistent state as some PHP file is brittle, error-prone (beware of code injection), and probably not very efficient. Several ...


-1

If you ask for my opinion and my advice. Go with MySql because in the previous years I have built application using a JSON data structure but it has been very hard to maintain (it might also be my luck of knowledge). JSON is cool and simple. I admit !! But not as powerful as MySql. Go with MySql. MySql Vs JSON


2

If you want to go with the file approach and have mostly static and configuration data use SQLite (PHP entry): it is a RDBMS just like MySQL, but it is a local single file in a directory of your choice (it can even be in your application's folder), installation free, lightweight and can accomplish your data requirements with consistency and a lot of tested ...



Top 50 recent answers are included