Tag Info

Hot answers tagged

62

C has a much, much simpler interface, and its rules for converting a source code interface into a binary interface are straightforward enough that generating external interfaces to bind to is done in a well-established manner. C++, on the other hand, has an incredibly complicated interface, and the rules for ABI binding are not standardized at all, neither ...


29

If you're trying to communicate with a speaker of another language, pidgin is easier than Shakespearean English. C's concepts - function calls, pointers, NULL-terminated strings - are very straightforward, so other languages can easily implement them well enough to call C functions. For historical reasons, many other languages are implemented in C, which ...


23

As I understand it, implicit conversions can cause errors. You're missing a word: implicit conversions can cause runtime errors. For a simple case like you show, it's pretty clear what you meant. But languages can't work on cases. They need to work with rules. For many other situations, it's not clear if the programmer made an error (using the wrong ...


20

C is one of the oldest languages still around. Its ABI is simple, and virtually every operating system still in use today has been written in it. While some of those OS's may have added stuff e.g. in C#/.NET or whatever on-top, down below they're very much steeped in C. That means that, in order to use the functionality provided by the OS, virtually every ...


20

For what it's worth, len(str(100)), len(chr(100)) and len(hex(100)) are all different. str is not the only way to make it work, since there's more than one different conversion in Python from an integer to a string. One of them of course is the most common, but it doesn't necessarily go without saying that's the one you meant. An implicit conversion ...


13

Implicit conversions are quite possible to do. The situation where you get in trouble is when you don't know which way something should work. An example of this can be seen in Javascript where the + operator works in different ways at different times. >>> 4 + 3 7 >>> "4" + 3 43 >>> 4 + "3" 43 If one of the arguments is a ...


8

ColdFusion did most of this. Define a set of rules to handle your implicit conversions, create a single variable type, and have at it. The result is total anarchy, where adding "4a" to 6 is 6.16667. Why? Well, because the first of the two variables is a number, so the result will be numeric. "4a" is parsed as a date, and seen as "4 AM". 4 AM is 4:00/24:00, ...


7

You're saying that implicit conversions could be a good idea for operations that are unambiguous, like int a = 100; len(a), where you obviously mean to convert the int to a string before calling. But you're forgetting that these calls may be syntactically unambiguous, but they may represent a typo made by the programmer who meant to pass a1, which is a ...


7

Once a language has been compiled down to assembler or even to say CIL or JVM, concepts such as if statements are lost as they are turned into branches. Not particularly in practice. If you look at a tool like Reflector, it will happily turn CIL back into pretty accurate C# code, ifs and all. So, having said all that, is there a language who's goal ...


6

Leaving out the details other answers already provide: The reason so many languages provides a C binding is that all *nix and Windows operating systems expose most of their OS API via a C interface. So the language implementation already needs to interface with C to be able to run on the major Oses. Therefore, it is straightforward to also offer directly ...


6

I see plenty of reason why you should embrace pre-processed languages, and I'll try to demonstrate the benefits of those tools. 1. Paradigm shift In my opinion, the greatest feature of any pre-processed language is the ability you to develop and solve problems in a different mindset compared to the standard HTML/CSS/JS way. In short, pre-processing can ...


6

There is no reason. If the semantics you're trying to express are fundamentally C-compatible and not something like templates, there is no reason you can bind easier if the implementation is written in C. In fact, it's pretty much by definition that a C interface can be filled out by any implementation that can meet the binary contract- including an ...


5

What is it about Haskell that has led to it's rise in popularity among experts in the FP world? There's a few of different things I've seen: It's novel. As much as FP enthusiasts poo-poo all of the fads in imperative and OO programming, they're still human. Lisp has been around since the 60's. ML since the 70's. A lot of people have spent a lot of ...


5

The overarching theme of your question seems to be succinctly summed up in the last paragraph: "What are the benefits to using these preproc'd languages, especially given the fact that they're not browser supported?" What's fantastic about preprocessors is that they don't need to be supported by the browsers. They are taking the non-native-web input and ...


4

Some intermediate languages have been successfully used as target for a lot of various languages, e.g. LLVM (or Ramsey & Jones' C--, which might be a dead project in 2015) Notice that an intermediate language does not carry all the information provided in the source language (e.g. you are losing information when compiling from C to LLVM). However, I am ...


4

Imagine for a moment the context of your statement. You say this is the "only way" it could work, but are you really sure it will work like that? What about this: def approx_log_10(s): return len(s) print approx_log_10(3.5) # "3" is probably not what I'm expecting here... As others have mentioned, in your very specific example, it seems simple for ...


3

Implicit conversions can be a real pain to work with. In PowerShell: $a = $(dir *.xml) # typeof a is a list, because there are two XML files in the folder. $a = $(dir *.xml) # typeof a is a string, because there is one XML file in the folder. Suddenly there is twice as much testing needed and twice as many bugs as there would be without implicit ...


3

I can't think of any downsides to this so long as your parser non parser sides are truly separate. If you end up implementing the same things twice, in two different languages, that is problematic due to bugs when they likely don't always behave the same ways, as well as duplicated effort. If that isn't going to happen, it seems like a fine idea and makes ...


3

Assembler languages are processor (or CPU) specific. Each processor has its own assembler language (which maps to a different machine language). So SPARC processors use SPARC assembler, x86-64 processors use x86-64 assembler, etc. For a few processors, including x86-64 used in most laptops & desktops in 2015, you might have two different syntaxes so two ...


3

I've developed a crawler in Python for educational purposes (TripAdvisor Scraper). It's built upon Scrapy for crawling the web and I'd choose Python because it is good for Natural Language Processing techniques, you have a lot of toolkit and resources (NLTK). Python is not so fast to process high volumes of data, and you have to deal with memory management ...


3

Sounds like the code in the middle is changing the value of the state variable, giving you different execution in the second switch statement. Presumably, this matters; create a new variable, store the value of state into it and use this in the second switch statement: int savedState = state ; switch( savedState ) { ... } // 0, 1, 2, 3 // Other Code ...


2

There are two major axes when interfacing with another language: the concepts that the interface can carry over: just values? references? generics? how the interface is implemented in "binaries" (called ABI) C has an advantage over C++ on those two fronts: C only has mostly simple concepts, which appear in most every other language1 The ABI of C ...


2

The only way for a conversion from language X to some intermediate language IL and back to be lossless is for IL to be a superset of X. If you want to have multiple languages as X, then IL has to be a superset of all of them. Therefore, I would suggest that IL has the following structure: delimiter: ---------SOMERANDOMSTRING---------- ...


2

Explicit casts are important for they're making your intent clear. First of all using explicit casts tells a story to someone who is reading your code. They reveal that you intentionally did what you did. Moreover the same applies to the compiler. The following is illegal in C# for example double d = 3.1415926; // code elided int i = d; The cast will make ...


2

I am going to focus on your core question, since other stuff has been answered elsewhere. Should you target a higher level language or assembly? Getting software done is hard. While making a new language can be pretty easy, you need to stick to simple stuff and avoid the stuff that is a pain to implement. Making your first language has the problem that ...


1

Because of the way the expression is parsed and evaluated, a sum function will get the results of the EnumFromTo, and therefore under normal conditions there is no way to get at its arguments. To receive the unevaluated arguments, you would need to use a macro. I don't know anything about Template Haskell, but supposedly it provides this ability. In ...


1

Do I lose any optimization opportunity if I choose to compile my language down to Java instead of the JVM bytecode? Opportunity? Sure. Your language knows about its semantics and its limitations. If you have certain features that could be optimized, then you can make those optimizations and output the better bytecode. If you go to Java, Java needs to ...


1

Here's a program that implements a similar code in C. Note that I removed all error checking for brevity: #include <sys/timerfd.h> #include <stdlib.h> #include <sys/epoll.h> static int pending_jobs; static int efd; struct cb_data { int fd; void (*fn)(void); }; static void set_timeout(void (*fn)(void), int secs) { struct ...


1

There are a lot of ads asking for "language agnostic programmers". They're looking for people who are okay with programming in whatever language is needed to get the work done. They want people who are totally fine with learning another language if that's what the project calls for. They're looking for people who aren't clinging to just one language and ...



Only top voted, non community-wiki answers of a minimum length are eligible