Tag Info

New answers tagged

0

Depending on your implementation language, there may be dynamic mappings or code generators to map XML to your object graph. If you don't want to go that route, I'd suggest using an event based parser rather than creating the XML document, then creating your AST from the events instead using recursive descent. So when you see the start of the value element ...


0

Comparing complexity of processing two different types makes no sense until it is not representing same data in these types.


2

When a browser makes an HTTP request, it looks like this: GET /search?q=cats HTTP/1.0 Host: www.google.com Connection: close … to which the server should send a response that looks like this: HTTP/1.0 200 Success Content-Type: text/html; charset=UTF-8 Content-Length: 1337 <!DOCTYPE html> <html> <head><title>cats - Google ...


3

The AST should only represent the syntax tree of your language. The objects making up the AST would generally not have any further functionality. Nice things like evaluating the AST or prettyprinting it can be implemented outside. I generally use the Visitor Pattern for these external methods – given that I implement an accept_visitor method for each AST ...


8

Executive Summary Excluding Big-Integers, Strings that are more than one character long are inherently more complicated than numbers because they: are represented as a list (or shallow tree) of multiple numbers can be alphabetized have case sensitivity have punctuation, accents, characters, and whitespace, which all need to be treated differently have ...


1

In the Boo language, which encourages playing around with ASTs via its metaprogramming facilities, there's an AST node class called CompileUnit that lies at the root of a compile tree. Its children are Module nodes, which represent a single source file, and each Module contains tree nodes corresponding to the AST of the code in that file. You could do ...


1

A web server is a program written in any programming language that handles "web traffic" over socket(s) adhering to standards/application level protocols (HTTP, etc). Most programming languages offer you to create a socket. Am I right in thinking that a server just needs some kind of interface such as CGI to make the server and the programming language ...


1

Its down to memory - an integer variable, for example, will occupy a set number of bytes and will never grow or shrink. A 4 byte variable remains like that and is copied around the system as-is, This means passing one into a function copies the value directly. Strings however, occupy a variable number of bytes and this makes them fundamentally different to ...


1

In my opinion, we use numbers, don't process them. If you are doing some kind of numerical analysis (which I do often) in any language, you'll use the numbers as input for formulas, for example. This is of course not necessarily always true, but usually true. Strings are "processed" more. For example, you don't make a script to put numbers to lower case, ...


4

I think there are two aspects to this, and your question was not entirely clear which direction you want to take. String operations from the perspective of the programmer can be easy depending on the language. Perl, for example, has regular expressions and other string operations baked into the language. It is trivial to transform or search strings. Other ...


1

This depends clearly on the programming language. For example, when using a language focused on numeric processing (like Fortran), or when using a language like C where "String" is not an inbuild data type, or at least not implemented as seemlessly and without a concat operator like "+" or "&" and garbage collection (like in Pascal), then string ...


6

One of the most important characteristics that make a programming language efficient is the closeness of the supported data types to the native data types of the underlying hardware. An int primitive directly corresponds to a machine word; it does not get any better than that. The moment you turn the int primitive into an Integer object you have degraded ...


7

Am I right in thinking that a server just needs some kind of interface such as CGI to make the server and the programming language work together? Almost. You need a web server that has some kind of software to allow it to respond to HTTP requests as well. Think about how a static page is served. The server retrieves the HTTP request, finds the ...


63

In the early days of the web, CGI was indeed the only (practical) way to have dynamic content (you could do named pipes of files -- and those were used in days before cgi, but that wasn't practical at all). CGI works by sticking a bunch of information in the environment of the process that is forked and then exec'ed (and possibly some in stdin) and then ...


18

Yes, any general programming language can serve to write the server-side part of a web site. However, the qualities of a programming language, in this subject as in other things, are usually only one of many factors that contribute to its popularity. For example, I reckon that PHP became popular for websites because: It is extremely easy to upgrade from ...


0

You can use some HTTP server library, e.g. libonion, even in your program coded in C (or C++, see also Wt). There also some HTTP client library (e.g. libcurl) You can use other HTTP libraries, e.g. ocsigen & ocamlnet for OCaml. There are several Web dedicated languages (outside of PHP), e.g. Opa, HOP, Kaya, etc... (both HOP & Opa can easily mix ...


1

I agree with what has been said but if you really want a memorisation system then investigate the Leitner cardbox system . You could write a program to implement this or google for flashcard systems etc. Another good way to recall technical details is to maintain a blog. The act of reflecting on what you have learned and then writing about it will reinforce ...


5

What you are saying is absolutely normal. As the British would say, "if you don't use it, you lose it" This however is not necessarily absolutely true. As Killan Foth pointed out in the comment above, your memory is much more complex than that. It keeps it in store somewhere, just harder(slower) to find (computer memory btw tries to mimic this, hence L1 ...


0

Writing a compiler to produce machine code may not be much more difficult than writing one which produces C (in some cases it may be easier), but a compiler which produces machine code will only be able to produce runnable programs on the particular platform for which it was written; a compiler that produces C code, by contrast, may be able to produce ...


3

The simple answer is thats the order the binary instructions on most processors are laid out. Back when men were men and sheep were scared assembly programers spent a lot of time looking at raw binary code (and sometimes trying to infer what instruction was hanging from the on/off lights in the control panel). It was just easier if the assembly code ...


2

I do not know what the deal is with sigils, other than perhaps to scare the uninitiated and to annoy those wise enough to know that they could have very easily been missing. Hopefully, another answerer will have more insight on this. (As ratchet freak mentioned in the comments, it was probably done this way in order to simplify the parser, which perhaps ...


6

The term "variable-length array" is actually specific to C, but it sounds like you're mostly interested in dynamic stack allocation. To review, VLAs are a feature added in C99 (then made optional in C11) which allow an array to be declared with a size not known until runtime. This means that the language must allocate space at runtime once it knows what the ...


3

Ultimately, it depends on the specification of the particular language that you are using, but in general, pass-by-value-result (Wikipedia) means that the original value of the caller will not be modified until the function returns, so the only reasonable thing to expect is that the value should remain unchanged in the event of an exception, because when an ...


2

As a CS student, I faced the same problem before I went to university. I know how a for loop works, but how does that make an iPhone app? I never tried and never figured out. But after started university, and actually being forced to start writing stuff for assignments, things just get easier. Because when you actually start working on things, you can learn ...


0

In general, you will encounter value types and reference types. With a value type, you don't care about the object that represents it, you care about the value. If I give you a value, you expect that value to stay the same. You don't want it to change suddenly. The number 5 is a value. You don't expect it to change to 6 suddenly. The string "Hello" is a ...


5

There are few possible reasons for this sort of thing: As in JacquesB's answer it may simply be convenience for the library user to call a single method rather than two methods and keep their code more succinct. Performance may be a consideration. Calling .substring(3) will result in a new string being created, and therefore you are looping over the string ...


4

These are called convenience functions. They are included so users can write shorter and simpler code. Note that almost every library is "redundant" in the sense that users could write the same code themselves outside of the library. However the point of using libraries is that you save time and code, and you can reuses the knowledge of the library in ...


6

Does the ML (SML/F#) implementations of tco in these languages differ substantially from the implementation in other languages, such as C++ and Haskell? Not as far as I know, no. The optimization of discarding the existing stack rather than saving off its current state (and possibly adjusting the execution pointer directly) on the last function call in ...


1

In C# there isn't much difference. The difference lies in what you can call on the reference you created. This code ICustomer customer = new Customer(); creates an interface reference named customer to the instance created by the new Customer(); call. This code Customer customer = new Customer(); creates an object reference name customer to the ...


-6

This question goes to the very heart of what Object-Orientation means. Simply put, in a language like Java, C# or Visual Basic.NET, classes (and structs) define Abstract Data Types and interfaces define Objects. As soon as you have a class or struct as a type (i.e. the type of a local variable, field, property or a method parameter, a method return type, a ...


10

As long as your code looks as simple like this void ExampleFunc() { ICustomer oCustomer = new Customer(); oCustomer.Method1OfICustomer(); oCustomer.Method2OfICustomer(); // ... } there is no semantic difference - you can exchange "ICustomer" by "Customer", and the behaviour will stay identical. In this example, however, it could fulfill ...


2

How you create it is not better or worse in any way. Let's think about it: You either set objects or get objects (i.e. passing them into a constructor, method or returning them from a method). In either case as long as you are providing an interface for setting and getting you can new up your object in any way you want because either way you will be able ...


17

There is one, very important distinction that I think that you're overlooking. The code you provided is for three things: the declaration of a variable, the instantiation of an object, and initializing that variable with that object. There is no interface implementation here. Customer needs to implement ICustomer (or do one or two other tricks) for that ...


0

I think, SQL is a syntactic sugar around relational algebra + something more. Relational algebra has a lot of power of functional languages, it indeed leverages functions of very high expressing power (selection, projection, renaming, join, union, intersection...). But s far as I know, basic treatment of relational algebra usually has no equivalent of lambda ...



Top 50 recent answers are included