C Programming Language 'Has Completed a Comeback' (infoworld.com) 243
InfoWorld reports that "the once-declining C language" has "completed a comeback" -- citing its rise to second place in the Tiobe Index of language popularity, the biggest rise of any language in 2017. An anonymous reader quotes their report:
Although the language only grew 1.69 percentage points in its rating year over year in the January index, that was enough beat out runners-up Python (1.21 percent gain) and Erlang (0.98 percent gain). Just five months ago, C was at its lowest-ever rating, at 6.477 percent; this month, its rating is 11.07 percent, once again putting it in second place behind Java (14.215 percent) -- although Java dropped 3.05 percent compared to January 2017. C's revival is possibly being fueled by its popularity in manufacturing and industry, including the automotive market, Tiobe believes...
But promising languages such as Julia, Hack, Rust, and Kotlin were not able to reach the top 20 or even the top 30, Tiobe pointed out. "Becoming part of the top 10 or even the top 20 requires a large ecosystem of communities and evangelists including conferences," said Paul Jansen, Tiobe managing director and compiler of the index. "This is not something that can be developed in one year's time."
For 2017 Tiobe also reports that after Java and C, the most popular programming languages were C++, Python, C#, JavaScript, Visual Basic .Net, R, PHP, and Perl.
The rival Pypl Popularity of Programming Language index calculates that the most popular languages are Java, Python, PHP, JavaScript, C#, C++, C, R, Objective-C, and Swift.
But promising languages such as Julia, Hack, Rust, and Kotlin were not able to reach the top 20 or even the top 30, Tiobe pointed out. "Becoming part of the top 10 or even the top 20 requires a large ecosystem of communities and evangelists including conferences," said Paul Jansen, Tiobe managing director and compiler of the index. "This is not something that can be developed in one year's time."
For 2017 Tiobe also reports that after Java and C, the most popular programming languages were C++, Python, C#, JavaScript, Visual Basic .Net, R, PHP, and Perl.
The rival Pypl Popularity of Programming Language index calculates that the most popular languages are Java, Python, PHP, JavaScript, C#, C++, C, R, Objective-C, and Swift.
Don't call it a comeback, it's been here for years (Score:5, Insightful)
Re:Don't call it a comeback, it's been here for ye (Score:5, Funny)
Re: (Score:2)
Back to school.
Re: (Score:2)
These days, whatevers-of-the month barely last a week.
Don't call Tiobe a reliable metric (Score:4, Insightful)
I'm not saying C did or did not come back, or did or did not go away. I am saying, you won't know from Tiobe, it way too random. They count language questions, not language usage, and don't make the slightest attempt to correct for predictable skew like selection bias due to who hangs out there as opposed to, say, stackoverflow.
My totally on reliable take on it? C dev population stays about the same: very few, very skilled, and very highly paid. Because of the latter, the number of C wannabes spikes from time to time, but don't worry, they will go away after they ask a few questions and still can't code.
Re: (Score:3, Informative)
C dev population stays about the same:
Some of us are getting quite old and have been dying off.
Re: (Score:2)
C programmers are not highly payed. ... now as those projects exist, the market has a serious demand f
Depending on region Java and C# developers are payed highest.
E.g. in London area C# developers with banking/finance experience earn about $1000 per day.
C developers in Europe not even make half of that.
OTOH C# is not very popular in Germany, we mostly do Java here. So you also can earn good money with C# skills in Germany, about $750 a day. (Not popular means: traditionally not many projects were done in C#
Re:C programs are too dangerous for net-connected (Score:5, Insightful)
Nah, I'm guessing browser tech such as javascript and flash, mobile apps with embedded malware, and on the server side PHP the cause for entry.
And now we're seeing our hardware itself is deeply flawed...from mobile chips to desktop to server to mainframe.
Re:C programs are too dangerous for net-connected (Score:5, Insightful)
Re:programming practices (Score:3)
Programming practices. Yeah ok.
But people are people, programmers are programmers, and there are bell curves of skill, care and attention, schedule reasonableness under which programs are created.
So let's not assume every programmer writing a potentially security-relevant piece of code is a really good, well educated in best practices, really safe designer and coder with enough time for testing and iteration. Assuming that would be naive.
So why not protect against common errors using the programming languag
Re: (Score:2, Funny)
> people are people
Maybe if you aimed higher than that, you would be a better C programmer.
Just saying.
Re: (Score:2)
So that's where all those C programmers who can avoid buffer overflows went, they ascended.
Shame we are stuck with the rest.
Re:programming practices (Score:5, Insightful)
But people are people, programmers are programmers, and there are bell curves of skill, care and attention, schedule reasonableness under which programs are created.
So let's not assume every programmer writing a potentially security-relevant piece of code is a really good, well educated in best practices, really safe designer and coder with enough time for testing and iteration. Assuming that would be naive.
It would be naive to assume general purpose language selection makes a meaningful difference with regards to security outcomes.
It's up to the architect to manage risk by selecting appropriate tools and methodologies to best address specific problem domain. Placing programmers in an environment that ensures failure by giving them the wrong tool for the job before them or where they are required to always be extra careful in order to avert disaster is extremely counterproductive.
So why not protect against common errors using the programming language constraints and checks? Most of these protections can be done with very little cost, performance wise or in loss of program expressive power.
It is not clear to me specifically what you believe is not being done that can be.
Compile time checks, static analysis, profilers, fuzzers and runtime bounds check code inserted automatically by compilers by default are generally available to programmers at little to no cost. Quite a lot of the old standard C library has over the years been marked as hazardous to your health by modern compilers.
We can teach drivers not to start the car engine with the car in "drive" because they might run someone over, or we can just design the car not to start except in park.
Obvious solutions to obvious problems already exist. Yet it does not follow obvious problems necessarily have tractable solutions. For example designing a car incapable of ever running anyone over is reasonably beyond current technology even though instances of reasonable measures to mitigate the problem exist.
One thing that has always fascinated me over the years is the lack of sufficient advances in outcomes commensurate with development and selection of new languages. Most instances of productivity gains and capabilities can be traced back to hard won incremental development of complex domain specific systems and hardware improvements rather than advancement of underlying general purpose language.
The fact virtually all system programming is still some flavor of C in my view speaks for the difference between hype, wishful thinking and reality. We've had decades and so far very little of substance to show for it.
Decade ago when processors that could execute java byte code natively were taped out I actually believed this would change. I assumed we would all be running java everything by now and this is from someone who personally never cared for the language.
Re: (Score:3)
Maybe we just need better automated testing?
C is easy if you don't try to do anything clever. Let the compiler be clever.
But often there is no testing at all. Maybe in the future everything you compile gets fuzzed.
There is absolutely no reason at all to think it is better to package this into the language, when it can be placed anywhere in the build process.
Re:programming practices (Score:5, Insightful)
We can teach drivers not to start the car engine with the car in "drive" because they might run someone over, or we can just design the car not to start except in park.
We can also design cars to be incapable of driving faster than 30 miles per hour, because that is determined (by a committee of "experts", of course) to be the maximum "safe" speed that embraces 99% of all drivers on the road.
We'd all just pay for this safety. Pay in time. Pay in convenience. Pay in no longer having any possibility of "racing" a car or pushing the performance envelope for cars. Pay in no longer permitting anybody, anywhere, to design a car that does NOT have the speed governor built right in, and use all of the other crap that the CoE decided was necessary for even a raging drunk to be safe behind the wheel, including the car-surround baby bumpers and reinforced passenger compartment and feature that won't let the car start without all passengers wearing a kevlar vest and safety helmet.
This is an argument that is as old as time. If you like working with a fascist language that only permits you do allocate memory through an opaque interface that cheerfully trades off speed for an illusion of security, there are many to choose from. C, it is absolutely true, has comparatively few safety nets, although there are tools and techniques for making it as safe as you like. It is also true that it is difficult to write more efficient code than one can write in C short of coding in assembler, and C allows one to inline assembler for those cases where only assembler will let you access certain systems features (instead of waiting until the CoE decide that they are "safe"). Similarly, even good old Fortran has its place if you are doing massive linear algebra and want to optimize it for bleeding edge CPU features.
Could one modify C a lot more minimally, to make it safer than it is by nature while still not enforcing the OO kool-ade and outright prohibiting the use of malloc and pointers? Sure, probably -- some of the tools out there basically do that. But there are times when one can write code with malloc and pointers that is just plain magic compared to what one can get with OO opaque memory management.
Re:C programs are too dangerous for net-connected (Score:5, Interesting)
Oh Lord, seriously? This again? C is more dangerous than Java the way that a KA-Bar is more dangerous than a butter knife. If you take a real programming language, hamstring it, put a bib on it, and pull its teeth so it can process nothing more than strained baby food, sure, it won't be dangerous but then again it won't do much useful either.
Write a device driver in Java or Python. Or a kernel. C will always have a place in net-connected computers. You just don't hand a loaded gun to a child and expect he'll produce something useful without blowing his foot off. C is for grown-ups and when you get big and strong and if you eat all your spinach maybe when you grow up you'll do system programming too. Until then, feel free to play around with interpreted languages that pen you in a coral so you don't do anything stupid and feel free to pretend that JIT really does mean it's compiled and just as fast as native code.
Re: (Score:3, Interesting)
I disagree. Too much of the modern economy now depends upon code to leave safety to the whims, skills or vanity of the programmer. Frankly, the "trust me, I'm good" argument isn't good enough and neither are you. Type safety, bounds checking, protected memory and access control are no longer optional in 2018. You either begin accepting these things or the product liability lawyers are going to win out in court eventually and you will be held financially liable for every bug in your C code. Software has long
Re: (Score:2)
It is easier to write a compiler in C for a safer language than to write everything in C.
Re: (Score:2)
This reminds me of a joke I heard once about a proctologist who had painted a room through the keyhole.
Many things are possible, but most of them are not practical and frankly shouldn't be done.
Re: (Score:2)
There are C macros and your can write all you want with them; OOP for example, can be emulated with just structs and pointers.
Except for destructors, which is necessary for RAII, provides a lot of the safety OOP in C++ provides.
Type safety is more or less a fallacy.
Type safety allows your compiler to perform a bunch of error-checking that dynamic types have to catch at runtime. I'm not saying one or the other is better in general, but for mission critical code, I know which one I'd rather have.
Re: (Score:2)
We see a lot of dynamic languages like Python or Lua and they are ok.
If time-to-market is your most important concern, then dynamic languages seem to do the job. My observation is that one reason why is that in a dynamic language, that fewer bugs have to be fixed before deploying. This is why languages like Python feel more productive than they are.
Languages with lots of static checking won't let you compile, let alone deploy, certain classes of bug, particularly if you wrote your code to use the static analysis rather than to circumvent it.
Re: (Score:2)
Re: C programs are too dangerous for net-connected (Score:4, Interesting)
Re:Oh lord, that again? (Score:5, Insightful)
Re: (Score:3)
Using more memory or more disk space is not inefficient.
A la contrair: it is nearly always more speed efficient than using less.
The historic reason why people tried to use less memory and less disk space is simple: there was not more available. Bottom line it does not matter at all if you squeeze your smartness to put a data structure and the relevant algorithms into the smallest amount as possible (of memory and disk space) or if you rather use your smartness to develop a maintainable, extendable, scaling,
not go (Score:2)
Go is less performant than java. Rust is on par with c++. They have nearly opposite design goals. Use go for server back end services, not kernels or drivers. The rest of your post is spot on. Citation is the benchmark game.
Re: (Score:2)
How come go is slower than java? It compiles to native code and is more low level (except for channels and goroutines). Do you have any idea how java is faster?
Re: (Score:3)
try{
for(i=0; i<10; i++){ if(i<0 || > a->length){
throw(zOMGEXception);
}
a->data[i] = i; }
catch(){
//The language feature doesn't relieve you of any responsibility
}
will always be marginally slower than
for(i=0; i<10; i++){
data[i] = i;
}
Re: (Score:2)
This kind of check is done in both go and java, it still does not explain why go is slower than java.
Re: (Score:2)
How come go is slower than java?
It isn't...at least asymptotically. Java doesn't have packed structs so it's going to be perpetually disadvantaged compared to Go in this area as Go's compiler improves.. And memory is way important these days when it comes to performance.
Re: (Score:2)
You do know that java byte code is only an interims representation and that the VM compiles the byte code to native code?
Bottom line I would expect Go and Java be equally fast ... however benchmarks are always only measuring niche parts of a language.
Remember when people arguing against C++ claimed that virtual (member) functions where only half as fast as non virtual ones? They did their benchmarks with empty function bodies and and no function arguments. It turned out that the vtable dispatch and call of
Re: (Score:2)
Bottom line I would expect Go and Java be equally fast
As I mentioned above, I'd expect Go to be ultimately faster due to more compact storage of stuff. (But on the other hand, pointer-heavy structures could be costlier since fat pointers replace object headers in Go. But on the third hand, a pointer-heavy module such as a graph library is likely to do its own bookkeeping and use integer indices, for example.)
Re: (Score:3)
How come go is slower than java? It compiles to native code and is more low level
Compiling to native code isn't always an advantage. For a trivial example, consider a Java and a Go code fragment that calls the same method on objects of the same type in a loop. In the Go version, because of the AOT compilation model, this will always be a function call unless the compiler can statically prove that the object type is always the same for every possible invocation of the program. The Java version will collect profiling information as it runs, determine that the same method is called ever
Re: (Score:2)
In the Go version, because of the AOT compilation model, this will always be a function call unless the compiler can statically prove that the object type is always the same for every possible invocation of the program.
On the other hand, my understanding is that Go's methods are (intentionally) sufficiently dumb that they can be called with an indirect jump that can be reasonably predicted by current breed of CPUs (with yet other millions of transistors besides branch predictors helping with parameter passing and faster return stack management - yet another symptom of current post-modern systems wasting transistors on things not actually contributing to computation). Having said that, if some of the method call parameters
Re: (Score:3)
On the other hand, my understanding is that Go's methods are (intentionally) sufficiently dumb that they can be called with an indirect jump that can be reasonably predicted by current breed of CPUs
That depends on whether you use an interface or not. If you don't, then it's equivalent to calling a final Java method (you can tell statically what the destination will be). If you do, then (as with Java) it's an indirect jump via a vtable. The problem with method calling is not so much the cost of the jump, it's the cost of call frame setup and of missed optimisation opportunities. For a small method, you may end up doing 2-3 instructions of real work, but 10-15 instructions of setup. Even if the jum
Re: (Score:2)
There is no reason a driver written in Go is slower than one written in C/C++, and the same is true for kernels.
Re: (Score:3)
FTFY
Re:Oh lord, that again? (Score:5, Interesting)
Attitudes like this are why people need a computer 600,000 times faster with 262144 times the memory in order to load something just to check their e-mail. I don't use Rust. I use Go when I must. It's not a bad language as new languages go - Syncthing, a project I've contributed to, uses Go and it's not terrible.
In a way you're correct. I'd agree that only about 10% of software really needs the performance and versatility of C. Most others can get away with C++, for better organization, or some other natively compiled code. Go if you like. Or Pascal if you want something old school but still strongly type checked. I actually use Pascal quite a bit myself, simply because of the free Lazarus environment. Even interpreted stuff has its place, but far less than it is used for. Just as only about 10% of software needs the power and versatility of C, only about 10% of software is appropriate for an interpreted environment. The problem is, kids coming out of school high on what some unfortunate profs (who often don't have to work in the real world) have been feeding them then start all these projects in Python and Java that have no place being written in an interpreted language. Python is good for small front ends. But then someone will want to get fancy and use PyGTK or some other frankenlibrary or else what started as a little front end simply grows beyond what is really appropriate and it becomes non-portable and a nightmare fast.
I actually have nothing against any language. I have serious problems when they are used inappropriately, though, and I have even more serious problems when what has been the best swiss army knife programmers have ever had for the better part of half a century is slagged in favour of some du jour. C never lost its place, and won't for the foreseeable future. For system programming it's not just unparalleled, it's often just simply indispensable. Computers are not people, they are electrical devices with bits and bytes, and sometimes you just need a language that embraces that rather than tries to hide it like its some dirty secret.
Re: (Score:2, Insightful)
Attitudes like this are why people need a computer 600,000 times faster with 262144 times the memory in order to load something just to check their e-mail. I don't use Rust. I use Go
Uh! You are hardcore!
I use a Mail.app
start all these projects in Python and Java that have no place being written in an interpreted language. .. o ... 1
Care to point one out?
For most people doing programming at home Python e.g. is an excellent language.
And as you seem to live under a rock: Java is no longer interpreted, since u
Re: (Score:3)
Because it is not American.
Re: (Score:2)
Seriously, why is pascal not used much anymore?
It kind of is. If you take Modula-3 and give it a curly braces syntax, you essentially get Java 1.0.
Programmers seem to like curly braces because they are visually lighter than Wirth keywords like begin and end; it's the same reason why we seem to prefer Haskell to ML given the choice.
If someone wants to re-engineer Object Pascal with a modern syntax, I would definitely appreciate it.
Re: (Score:2)
Golang with its ad hoc interfaces, ever changing specs, missing apis, and dynamic typing when generics are needed, may end up introducing just as many security holes as c if it becomes popular.
Re: (Score:3)
Re: (Score:3)
Someone who thinks that C is the only performant programming language today? Someone who's never heard of Go or rust...
C and c++ (same code generator) kick the tails of go and rust, the former more so.
Re: (Score:2)
C and c++ (same code generator) kick the tails of go and rust, the former more so.
That's not true in the case of Rust.
The Rust code front end is less mature than the C and C++ ones but Rust has almost the exact same set of advantages and disadvantages for optimizaton as C and C++. This is intentional: they all mave more or less the same machine model.
Re: (Score:3)
Why intentionally sacrifice performance? Todays processors may be many thousands of times faster than the early ones, but it doesn't make sense to then slow them down with overweight inefficient code.
Performance and efficiency is still very important, slow code costs money in extra execution time, increased power consumption, increased hardware requirements, especially at large scale. Code which is 10% slower running on a single user's desktop might not make much of a difference, but run that code across th
Re: (Score:3)
Actually there are plenty of highly interesting and good paying projects for which C is the only real option. A decade ago I was a C and C++ programmer, and pretty good if I say so myself. I cared to write bullet proof and well documented C code, and companies paid me a lot of money to do just that. I wrote firmware for the 2000 series Texas Instruments DSP to control the semiconductor for a telecom laser. That was all C without even standard libraries because the DSP only had a couple K of RAM and ROM.
I wr
Re: (Score:2)
Well, those jobs likely will always exist. ... and then you simply would ask yourself: why not using C? /. who think to be a "magician" amoungst "mere programmers" you need to kn
But I doubt they need "special skills", you only need to know the hardware and its limitations you are on.
Would not matter if you address the same problems on said hardware in assembler or pascal or Java.
You would not have a JVM, though, but would need a java to nativ e compiler
Anyway, I was more complaining about the idiots here on
Re: (Score:2)
C is a fairly easy language to learn and understand. I basically had only 2 'special' skills that were very much appreciated by the senior engineers in the companies where I worked. the first one was that I have a masters degree in electronics and had theoretical physics as a hobby when I was in college. So aside from being a good programmer, I had the knowledge to understand the physics and instruments I was dealing with, which was a real benefit.
And my second 'special' skill was the fact that I wanted all
Re: (Score:2)
I am one. But I agree, C sucks. I am glad that my Pascal days have taught me not to try to be clever when developing software.
Re: (Score:2)
In my opinion Pascal is still the best language to teach programming.
And it does not lack anything to do serious developments in it.
Re:C programs are too dangerous for net-connected (Score:5, Insightful)
No bounds checking, no type checking. In 2018. Get serious.
A halfway good programmer doesn't need to trust the language to do that for him and is capable of ensuring boundaries. The problem is that halfway good programmers have become scarce, and today's coders are content to leave critical parts to a compiler they don't understand and black box libraries they don't know what do behind the scenes. So they need the handholding.
Re: (Score:3)
A halfway good programmer doesn't need to trust the language to do that for him and is capable of ensuring boundaries. The problem is that halfway good programmers have become scarce,
Halfway good programmers have ALWAYS been scarse.
Even if I was a great programmer in general, I sure wasn't last week when I was sleep deprived and my head felt stuffed with wool because of having a cold.
Re: (Score:2)
Hypocrite much?
and black box libraries they don't know what do behind the scenes.
That is exactly the point about a black box library. You should not need to know what is going on in it.
No, they don't need hand holding. If they needed to know what is going on in the black box: then they would need hand holding.
Unless you have read the most basic C manuals, you usually don't need to know how strlen() and strcpy() is implemented. Fortunately or unfortunately however they make good examples about the strength
Re: (Score:3)
The basic job of a programmer is to automate things: to make a computer do things, rather than a human. That is the entire point of all programming. What kind of programmer, when faced with a problem for which there is an existing generic solution with adequate performance prefers to write an ad-hoc solution? A poor one. Yet that's exactly what you're advocating: your notion of a 'halfway good programmer' is one that doesn't make use of the results of programming.
There are places where manual memory ma
Re: (Score:2)
Maybe expecting and getting a programming job that requires experience to do well without that experience (so the employer doesn't have to pay you as much) is more the issue, or could it be that language
Re: (Score:2)
Discipline and self control needs to be taught, or acquired by experience. Experience means making mistakes and learning from it, which bottom line means: you have to realize you made a mistake, or worse, someone has to point it out to you!
No one wakes up in the morning after he had read "programming language X" manual and suddenly knows what kind of discipline and self control he needs to use to work in that language (with its libraries).
Knowing what a buffer overflow is and knowing how to program so that
Re: (Score:2)
and buffer overflows are usually trivial to prevent, and even actively search for possibilities
Says the one who never programmed one?
If you only program in your small world then avoiding them is relatively simple. As you are AWARE that there could be a buffer overflow.
As soon as you have to treat data coming from the outside, that is a different matter. Most people are NOT AWARE that this here:
/*
* Doc:
* buffer will be \0 terminated when read from disk
* buffer will be \rs terminated
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
computers.
No bounds checking, no type checking. In 2018. Get serious.
My guess is C programs are the underlying reason for a good majority of ways of hacking into systems.
I mean a buffer exploit? Seriously? In 2018? Why in the hell would that be remotely acceptable?
No, sloppy programmers are the major reason for a good majority of ways of hacking into systems (Meltdown/Spectre notwithstanding).
Exclusively teaching and using bounds-checked, garbage-collected languages are a great way to produce more sloppy programmers.
Re: (Score:2)
computers.
No bounds checking, no type checking. In 2018. Get serious.
My guess is C programs are the underlying reason for a good majority of ways of hacking into systems.
I mean a buffer exploit? Seriously? In 2018? Why in the hell would that be remotely acceptable?
^^^ Another internet person that doesn't know what the fuck he/she's talking about.
News at 11.
Re:C programs are too dangerous for net-connected (Score:4, Informative)
Actually I think SQL injection probably accounts for a larger share than overflows
I don't have a more recent statistic, but an MSR study from 2012 found that around 70% of all exploited security vulnerabilities are buffer overflows.
Re: (Score:2)
More Popular? (Score:2)
both indexes are search popularity rankings (Score:3)
These aren't measures of how much languages are used, they're useless bullshit as asking which languages generate the most Twitter Tweets? Facebook posts? News articles?
Number of jobs held would be interesting.
So would number of unique jobs openings for each language.
Re: both indexes are search popularity rankings (Score:2)
Job adverts are certainly an interesting method but never the whole story. I've been checking job listings since the 90s for python and up till about 3-4 years ago where rarer than hens teeth (there's a tonne now since the management types finally discovered it). But all that time there was a huge amount of local devs using python for personal projects , glueing things together with it in server racks, holding conferences and meets and so on. Hell one of the founding devs of Django even lives near me. But g
Driven by Raspberry Pi? (Score:4, Interesting)
Re:Driven by Raspberry Pi? (Score:4, Interesting)
You can use more advanced programming languages on the Pi that have decent execution speed too, like Java or C#. I think C's popularity is more driven by Arduino, where other alternatives don't exist.
Re: (Score:3)
Except the fact that Arduino IDE uses C++ not C.
Re: (Score:3)
Re:Driven by Raspberry Pi? (Score:4, Informative)
The idea that a RPi is too slow for a high-level language to be fast enough is astonishing.
[1] In Smalltalk, integers are immutable instances of the SmallInt class, which is typically implemented as a tagged pointer. If integer arithmetic overflows, the result is an immutable instance of the BigInt class, which is stored as a pointer to an arbitrary-precision integer object. It's depressing how later dynamic languages, particularly scripting languages, haven't managed to have as useful integers. Smalltalk also had a variety of floating point types. It did not have things like if statements in the language. True and False were singleton subclasses of the Boolean class, which implemented methods like ifTrue: and ifFalse:. These took a block (closure) as an argument and either executed it or didn't execute it, depending whether they were True or False.
Needs updating (Score:2)
Re: (Score:2)
Re: (Score:2)
It isn't specific to a single CPU, this category of instructions are also found in ARM and PowerPC, even the PDP-10 provides hardware support for counting trailing zeros in an integer. Counting leading/trailing ones or zeros is common in many problems such as compression algorithms. And on platforms without FPUs, the compiler would emulate floating point instructions in software, so there's precedent for providing C language support for instructions that aren't available on every CPU.
Re: (Score:2)
Re: (Score:2)
A good compiler will convert a loop for finding the bit into the single instruction.
Re: (Score:3)
If your C standard library doesn't have ffs(), then... sorry, Windows user. I guess there's always _BitScanForward or __lzcnt.
Oh, and if your CPU uses clz to count trailing zeroes, you should report that as a bug.
Synthesizing ctz from clz (Score:3)
if your CPU uses clz to count trailing zeroes, you should report that as a bug.
Not necessarily. Use s = (s & (s - 1)) ^ s to clear all 1 bits other than the least significant, giving a "one-hot" integer. Then you can count leading zeroes and use that to infer trailing zeroes. It might look like the following (in a generic pseudo-assembly language):
Re: (Score:2)
In Standard C, how do you find the least significant set bit of an integer type?
Is this a trick question? Something like this in a #define, I suppose?
for (i=0;iwhy you would need to do that - chances are that you're complicating things when you don't need to, and just need an & operation. If you stumbled upon this when trying to do netmasks, be assured that the problem is already solved, and quite efficiently too.
C is helpful in making you think and find simpler algorithms, which execute far more efficiently than bloated libraries and language intrinsics that have to deal with ca
Re: (Score:2)
Oops, forgot about slashdot parsing <
for (i=0;i<sizeof(var)<<8 && var % (1<<i); i++);
Re: (Score:2)
I think you meant & instead of %.
In any case, there are better ways to do this: http://graphics.stanford.edu/~... [stanford.edu]
My favourite is the second example using only AND operations with constants. It's faster and has more predictable execution time, although it's not constant.
I seem to recall that some systems (BSD?) have a prototype function for this in their standard library too, which on some CPUs complies to a single instruction.
(s & (s - 1)) ^ s (Score:2)
In C or Python, running an unsigned integer through (s & (s - 1)) ^ s will give you only the least significant 1 bit (1, 2, 4, 8, 16, 32, etc.). For 60 (0x3C), it gives 4; for 1280 (0x500), it gives 256 (0x100).
This really only indicates where jobs are now... (Score:5, Insightful)
No one is seriously going to try to use C for front end web development, just as no one is seriously going to try to use Javascript in an embedded microprocessor. So what this study is doing is just pointing out where the current jobs are.
Trying to compare languages, is like asking "which is better? a band saw or a screw driver?". They're entirely different. And anyone who doesn't understand that, simply doesn't have enough experience with other programming tools yet.
Re: (Score:3)
You are right in general...but wrong here.
This report is not a beauty context or any other comparison of tools but rather statistics of web searches. As such it got reported and misinterpreted as "popularity" as if it was a preference.
Re: (Score:2)
Re: (Score:2, Interesting)
Re:This really only indicates where jobs are now.. (Score:4, Informative)
just as no one is seriously going to try to use Javascript in an embedded microprocessor
I draw your attention to JerryScript, developed by Samsung as a lightweight JavaScript interpreter specifically designed for running in embedded microprocessors.
The language stack is sorted out (Score:5, Insightful)
I consider this the transition to a more stable period. For some time it was unclear how functions would be split between programming languages. All kind of ideas were in the room, with interesting new contenders. Still the programming community decided that the areas covered by Java, Javascript, C, Python are well distributed in the way in which they are and that "good enough is still good".
C# (competitor to C++ and Java in my eyes) seems to be dying. Swift doenst take over from objective C as fast as that one is going down. So for low-level languages nothing else is left. OOP and Data Architectures are firmly in the hand of Java, which has a very small overlap and a very good synergy with C. Python coesists in other areas, and hurts neither of he two languages.
So in some sense: the war is over and java, (C+C++), python, Javascript have won for now.
C is still king, thank Engineering Schools (Score:5, Interesting)
Everything on planet freaking earth has firmware in it now and guess what compiler makes the smallest binaries that can talk to hardware?
Yes, that's right C.
Python can talk to C, but you aren't going to write firmware or low level interrupt handling code (like reading IR pulses) or monitoring an I2C bus.
Java is C's fat lazy son that lives in the basement and consumes all available resources can do things eventually, if you give him enough resources, time, and be able to tolerate the odor.
As long as computer architecture remains constant, C will be king. It's fast, small, and get's sh*t done now. Plus once you write it in C, you can call it from any other modern programming language like Python, Java, Objective-C, Swift, etc ...
I went to a graduation party of a graduating Aerospace engineer last weekend and his advice was learn C, learn simulation and solving software like Mathematica, learn how to work in teams, and be multidiscipline in career focus for great success. He graduated from Perdue.
Re: C is still king, thank Engineering Schools (Score:5, Informative)
You cannot write device drivers in Java or Python as both languages require either an interpreter alias virtual machine or a just in time compiler. Also they are not the right tool for that particular job. However, they are well suited for other tasks.
Re: (Score:2)
If you learn Java or C++ you automatically have learned C. Besides the preprocessor and the linker. ... cough cough cough. C is not much used in the air space industries, besides what your "Aerospace engineer" thinks.
And
Re: (Score:2, Insightful)
If you learn Java or C++ you automatically have learned C
I knew some of those Java guys and saw their C. Their initial contracts generally expired without renewal and their projects were scheduled for a complete rewrite. There are worlds of difference between these languages and anyone going at C as if they were writing Java or Java as if they were writing C is going to cause a lot of pain.
Re: (Score:2)
If you learn Java or C++ you automatically have learned C.
I can tell that you know nothing about C, and probably not much about Java or C++ as well.
how much is it used is almost KLOCs (Score:2)
Turbo Pascal (Score:2)
So when is Turbo Pascal coming back? ;-)
Re: (Score:3, Informative)
Lazarus [lazarus-ide.org] gets you the Object Pascal derived syntax from Turbo Pascal and Delphi, and provides an IDE available on multiple platforms. I've had zero problems installing it on several systems, mostly for quick and dirty projects where I didn't necessarily want to use C.
Re: (Score:3)
Well,
joking aside there is a quite complete and portable Pascal: https://www.freepascal.org/ [freepascal.org]
Search index = popularity? (Score:3)
Or maybe it's a reflection that nearly every developer out there knows C to some degree and doesn't have to search for help as much?
Maybe it means there are more older C devs that are more likely to go to a book than Stack overflow?
Either way, it's a garbage metric designed to generate lazy clickbait articles, like this one.
Yep...you also forgot bash. (Score:2)
Really you can accomplish everything in C, Java and BASH.
Build and deploy thousands of machines, and you don't have to throw 30 plus years of systems engineering under the bus because some idiot out of college wants to use python.