New answers tagged

0

In computer science, a function or expression is said to have a side effect if it modifies some state or has an observable interaction with calling functions or the outside world. From Wikipedia - Side Effect A function, in the mathematical sense, is a mapping from input to output. The intended effect of calling a function is for it to map the input ...


4

When Java encounters this + operator, it compiles the addition to byte code, specifically an iadd instruction. What the computer does when executing this instruction depends on how the virtual machine on which this program is executed was programmed. It might delegate to an ADD opcode from some processor's instruction set. It might consult an internal ...


1

It always boils down to address space. In a modern computer, any address space is a power of 2. E.g. you can fit 256 different values in a byte (2^8), 65536 in a 2-byte word (2^16). Directly related to that, memory sizes only come in powers of 2. Expressing these values as decimal does not "fit" the address space, meaning you do not run out of digits at the ...


7

Computers use Binary Code. Binary is used to encode both instructions and data. This is because transistors store and manipulate binary very nicely. It turns out that with enough boolean operations, you can perform the mathematical operations of addition, subtraction, multiplication, division, etc... It is possible to use a base other than binary, but ...


3

You remember the old adage "garbage in, garbage out", well, this is what static typing helps to prevent. Its not a universal panacea but the strictness over what kind of data a routine accepts and returns means that you have some assurance that you're working correctly with it. So a getAnswer routine that returns an integer will not be useful when you try ...


0

This is what JITters do. It's a good idea, but it won't help performance unless you do it for innermost code - i.e. the code where the program counter is most often found. There's little to be gained by optimizing code that is relatively seldom executed. It the program spends most of its time waiting for I/O, then optimizing it will also not help, not ...


0

There is a longer history of implementing languages by converting them to a second language and then with compiling it interpting the. C++ and NO were both done this way.


1

Would that be considered as a bad practice/idea? Enh? My first instinct is that you wouldn't gain much in performance. Spinning up a new process and sending in the data is a bit heavyweight. My second instinct is I'm not sure how general you're going to be able to do it. Just because methods return no data doesn't mean they don't work with data. You're ...


8

You seem to have a few misconceptions about working with large static projects that may be clouding your judgement. Here are some pointers: even if you declare the return type of a function, you can and will forget it after you've written many lines of code, and you will still have to return to the line in which it's declared using the search function ...


15

More over, with REPLs it's trivial to test a function for it's return type with different inputs It's not trivial. It's not trivial at all. It's only trivial to do this for trivial functions. For instance, you could trivially define a function where the return type depends entirely on the input type. getAnswer(v) { return v.answer } In this case, ...


6

Because static checkers are easier for statically typed languages. At a bare minimum, with no dynamic language features, if it compiles, then at runtime there are no unresolved functions. This is common in ADA projects and C on microcontrollers. (Microcontroller programs get big sometimes... like hundreds of kloc big.) Static compile reference checks are ...


4

I never understood statements like this one. To be honest, even if you declare the return type of a function, you can and will forget it after you've written many lines of code, and you will still have to return to the line in which it's declared using the search function of your text editor to check it. It's not about you forgetting the return type -- ...


17

Think of a project with many programmers, that has changed over the years. You have to maintain this. There's a function getAnswer(v) { return v.answer } What on earth does it do? What's v? Where does the element answer come from? getAnswer(v : AnswerBot) { return v.answer } Now we have some more info —; it needs a type of AnswerBot. If we go ...


6

What is the connection between type inference and advanced type systems? There are three things off the top of my head: Language designers interested in type systems will focus their language design around them. This means that all sorts of type oriented features were considered/implemented - inference being one. ML had it, so when follow up languages ...


4

The C++ syntax is designed in such a way that a declaration always needs a type to distinguish it from assignment. You simply cannot leave out the type, because that already has a different meaning: int i = 1; // Leaving out the type turns it into assignment: i = 1; int i; // Leaving out the type turns it into evaluation: i; You simply need an explicit ...


5

I don't believe such a possibility was ever considered by the C++ committee. Further, although FORTRAN did have a sort-of implicit type system (variables starting with 'I' through 'N' were integers, everything else was real) I can't quite see how such a thing would work in a block-structured language like C++. For example, consider code like this: int f() {...


8

In 1963, Tony Hoare proposed adding implicit type rules to ALGOL. The ALGOL committee boxed his ears, HARD. Requiring variables to be declared explicitly was known, EVEN THEN, shown to reduce errors in programming. Tony mentioned this in his Turing talk, and said it was BEFORE the probably-apocryphal Venus probe FORTRAN story, where a typo in a FORTRAN DO-...


5

Allowing optional types where they used to be required can make the syntax ambiguous. It is easier to add a keyword (or to reuse one in this case) than changing the grammar.


0

There is no contradiction here. Machine Learning Programs can learn by themselves to arrive at a solution, without having been explicitly programmed for that solution. But of course, someone has to write the Machine Learning Programs. It's exactly the same as with any other program. You don't need to know programming to use a web browser, but you do need to ...


0

You use programming to build a machine that can learn without you having to do any more programming. You use programming to build the machines mind. The mind goes on to learn things that were not programmed into it but learned by experience. It's not as powerful as a humans or even an ants mind, but there are many problems in computer science that are ...


0

What it's saying is implementation (or product) of machine learning provides computer with ability to learn. Machine learning as subject of study focuses on the development of the machine learning implementation. You can use general purpose programming languages (C#, Java, etc.), maybe you can use SQL (if you try hard) but not HTML/CSS. I suppose, since data ...


8

First of all, it seems to me you are missing (or perhaps misunderstanding) the "explicitly" bit in "without being explicitly programmed" (from the quote in the question). It doesn't mean that no programming is required at all, it means that you are not programming a specific solution to the problem, but instead what you are making is a more general program ...


-2

wouldn't it take longer to stream the file vs sending whole file at a time? Welcome to the time space tradeoff. Reading a whole file into memory (say as an array or string) is called slurping. It can be a good or bad idea depending on file size, available memory, and how many times you do it at the same time. The alternative is line by line processing (...


0

Let me introduce you to some tools that will help. Google images is a great place to find examples: I found that by just typing "flowchart number input sum" and looking for one that repeatedly takes input and uses a do-while loop Now sure, it's not exactly the same as your code but unless you're asking me to do your homework for you (which is not what ...


0

First, I'll repeat that a modulo b should be equal to a - b * (a div b), and if a language doesn't provide that, you are in an awful mathematical mess. That expression a - b * (a div b) is actually how many implementations calculate a modulo b. There are some possible rationales. The first is that you want maximum speed, so a div b is defined as whatever ...


1

A singly-linked list is the simplest persistent data structure. Persistent data structures are essential for performant, purely functional programming.


-3

Look up the "one instruction set computer". It is possible to design a computer that is Turing complete yet has only one instruction. The assembly language of such a computer is pretty minimalistic:-)


1

In just about any programming language, you can pass some type of list, array, tuple, record, or object as the only argument. It's only purpose is to hold other items instead of passing them to a function individually. Some Java IDE's even have an "Extract Parameter Object" feature to do just that. Internally, Java implements variable numbers of arguments ...


0

For non embedded system but something I was doing in C# was SCADA system. There were many events linked to what was happening in the warehouse when load was unloaded part of system generated event and other part was writing new state to the database. We of course had some GUI client but it was just to show state of the database which was reflecting state of ...


-3

I can tell you that by personal experience, because at our school, we had to create our own language, own compiler and own interpreter. I suppose you know, what the language and compiler is, so I will skip that. The compiler will create some structure from source code, that is executable by interpreter. It is up to you, how the structure looks like and how ...


4

Your question is too broad to be answered in a few paragraphs. And actually interpreters do not mean much: the BASIC interpreter of the ZX80 (in 1980) is really different from today's Guile, Lua, Ruby, or Python interpreters on most Linux systems. Knowing several programming languages, e.g. by reading Scott's Programming Language Pragmatics, is worthwhile. ...


2

An interpreter is feed a program represented as a data structure, then it steps through each of the tasks in the data structure and performs the tasks as it goes. The data structure can be a abstract syntax tree of the code you wish to interpret, or it can even be a byte-code if you wish. Interpreters may also hold on to a table (hash map) of variable names ...



Top 50 recent answers are included