Variable name length in C vs newer languages [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
It seems to me that C programs should tend to have longer variable names, since the names will be destroyed by the compiler and won't make any difference to the performance or binary size of an optimized executable. I don't understand why in fact the opposite happens, in newer, interpreted languages where the name of the variable/method can actually affect performance, variables and methods routinely have much longer names compared to those in C. Is it just a product of the times, or is there a real reason behind this?

This is a pretty subjective question--it probably depends on who you ask. But if you ask me, the reason is that C is not Object-Oriented, and is an old language that has a lot of developers following old rules. There's no good reason not to use descriptive variable names in C--you're right, the compiler discards things like variable names anyway.
But the teachings of descriptive naming are still relatively new (relative to, say, the existence of C). So I think the reason that descriptive naming is more prevalent in modern languages is simply because the same group of people that tend to change and adapt to these new methodologies, also are more open to using newer languages.
But again, OOP is a very core reason as well. The Java Coding Conventions of old put a lot of focus on naming things clearly, and that has permeated the culture of Object Oriented Programming. You'll find that C++ projects often use longer, better names than C projects.
Short code should never be your goal. Even in languages like JavaScript, where the amount of bytes transferred can affect performance, use names that are descriptive (but not too verbose), and minify it later using the many available minification tools.

Computers have gotten so staggeringly powerful that shorter or longer variable names make very little to no difference. But poorly named variables and functions, in any language, can cost a whole lot more money and waste way more time than any perceived performance hit you might take from using a longer name. The extra nanosecond of processing costs nobody anything, but the 45 minutes it takes a senior developer to figure out what the code is even doing costs everybody something.

Related

Can one create an OS using JS or PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
This is a question of interest, There are a number of interpreted languages that can be used to create an OS, Can one create an Operating system using PHP or JS.
It does not have to be a fully-fledged OS, at least the one that prints Hello World.
Regards
All three of those languages are Turing-complete, so they can simulate any other Turing-complete language. An operating system written in one (or a few) Turing-complete language can also be written in another, assuming that sufficient access to the underlying hardware is provided.
Whether such a thing could be made to be run any any reasonable speed is another matter entirely.
The number of things you can do in programming is virtually limitless, but many of those things require a lot of effort.
The main purpose of an operating system is to provide an interface between application programs and the computer hardware, often abstracting away details. In order to do this, the OS code must be able to access the hardware directly (or almost directly, e.g. by calling BIOS functions).
High-level languages like PHP and JavaScript don't have any mechanisms to do this. They depend on an operating system to provide access to hardware at a high level: files, network sockets, etc.
These languages do allow you to link in extension libraries, which give them extra capabilities. But then you're not actually writing the OS in these languages, you're writing it in the language that the extension is written in.
I don't think even C can be used to write an OS if you just stick to the portable features of the language. Operating systems written in C depend on implementation-dependent features such as casting integers to pointers, they use extensions like asm(), or they occasionally link with subroutines written in assembly, on order to get direct control of the hardware.

Should I use ES6 on a node.js API due to performance reasons? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
Given that V8 execution of ES6 code is slower on some operations, compared to ES5.
According to this: http://incaseofstairs.com/six-speed/
Can anyone point to an article/paper/post where tests were performed in order to find out if such performance difference will impact in the normal operation of an API developed with node.js?
Should I use ES6 or greater to build a node.js API, considering it is slower to ES5?
That's a false premise right off the bat, as demonstrated by the chart you linked to.
No, this is not "premature optimization"
Yes, it is. Choice of language dialect is much more about ease of development, compatibility with libraries, and reliability. There is nothing in common implementations of ES6 that are "slower" across the board. You haven't even built your application yet, and you're worried about something that is unlikely to make a significant impact at all.
If you find that there some particular code that could be optimized, Node.js allows you to implement native binaries where you can optimize all you want.
I know some may wonder, if the API is going to get millions of hits, but again, I'm more interested in the correct pattern to use.
Use ES6.
In the back-end, we're talking about hundreds or thousands of clients, and that performance hit will be compounded.
And yet, you don't even know what the pain points are in your application because you haven't built it yet. For most applications, it's going to come down to I/O.

What are ways to optimize scripts on js? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I noticed, that JS scripts consum a lot of RAM. Particularly, client side socket.io + node.js.
What are ways to optimize scripts on js?
What to look for in the first time and what do standards exist?
You can use some compressor to minification, sometimes I use the grunt properties or https://github.com/mishoo/UglifyJS, or you can do it online here http://jscompress.com
If you have to many files.js to import, you can use requireJs to manage it. http://requirejs.org/
The answer is: you do not need to optimize your scripts, at least not until you have a clear, overriding reason to do so. JS scripts consume as much memory as they consume. The engine manages memory and garbage collects. There is nothing specific you can do to reduce memory consumption other than processing less data, or using fewer libraries. 138MB is not a horribly large footprint, why does that bother you? If you decide that you really have nothing better to worry about than memory usage, then run a profile using your favorite browser devtools. However, if the usage is in someone else's code, and not your own, then there's not really anything you can do except, as I said, get rid of their code and do without it, or replace it with something else.
Not clear what you intend to mean by "what do standards exist". What kind of standards do you refer to? Do you mean best practices? Best practices, as I said, are not to worry about this, unless you are a library author and are trying to optimize your own library, OR, if you suspect a memory leak, which does occur but less frequently than one might think.
Add the scripts to bottom of the html content or can load the script asynchronously.

Is there a reason to use Scheme over JavaScript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
As far as I know, JavaScript can be used to do everything that is possible in Scheme.
Every functional programming paradigm I've learnt in Scheme is doable in JavaScript.
I know that one may end up using JavaScript to write ungood code (ones with global variables, too many states and side effects) where as Scheme restricts one to write functional code.
But apart from that, is it really necessary to use Scheme anywhere over JavaScript?
For those of you who say JavaScript can be interpreted only on a browser kindly draw the same question to Python and Scheme.
Let me pose a similar question:
Is there a reason to use French over English? Anything that you can express in French you can express in English, so is it really necessary to use French over English? Kindly draw the same question to Russian, German, Spanish, or any other spoken language you choose.
No programming language is completely unique, anything you can do in one language can be done in a different language, some implementations might require a bit more creative thought but it can still be done.
Some reasons to use Scheme instead of JavaScript or Python:
You appreciate the simplistic and minimalist structure of the
language
Ease of implementation when compared to expressive power (lambda
expressions)
You are more familiar with Scheme
The client has existing code in Scheme
Specific implementations or algorithms might have a min/max calculation available to give exact benchmarks, but you would have to look at specific algorithms. In general there is no way to define one language as always better in all situations (or even 'never worse'), and trying to pigeon hole oneself into a single language is dangerous. In my opinion, open mindedness is one of the biggest strengths a programmer can have. Being able and willing to use different languages or techniques can be a powerful tool.
I personally suggest further reading by looking up Polyglot Programming. It isn't directly related to your question, but it is a mentality that speaks to the benefits of knowing and using a variety of languages.

Should I use Lua? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am going to work on my new project where client has demanded to use 'Lua' if possible, I have never used it before and by searching on it I found it is fast compare to javascript and getting popular nowadays.
As I am very confused I had never use it before so I want to know something
Is it really better(in terms of performance and use) then javascript?
Will I get enough resources(because I don't want to move over after starting development due to lack of resources or it becomes hard to me develop)?
Will it needed anything other than C compiler to run?
Please guys it is really important to know about such thing before starting. Any help will be appreciated.
I'm assuming you're writing a standalone application in C or C++, and you're looking for a language to enable people to extend that application by embedding another language. That's pretty much Lua's territory.
Lua's strong point is that it's very easy to embed in your (C) application. It compiles quickly, it's tiny, licensing is liberal and using C functions from Lua is relatively easy. Standard Lua has enough performance for most things you'd use a language like this for; if you need more raw speed you could look into LuaJIT, the JIT-compiler for Lua.
As for your questions:
LuaJIT will probably be pretty much as fast as you can get for a dynamic language. Lua is used in games (Sim City, Far Cry, World of Warcraft), where performance is very important.
If by 'resources' you mean documentation: sure. Lua is a very simple language, much simpler than JavaScript; the manual should help you get started with the language itself, the wiki is tasty for tips about the embedding process. This article has an example you can copy/paste.
Lua pretty much runs everywhere a C program will run. It doesn't even need an operating system, and it doesn't depend on anything at runtime if you bundle it correctly.
Embedding a full JavaScript environment in your application, and interfacing your application to the JS environment, can be a lot of work (even though Google's V8 engine has some functionality to help you; see here).

Categories

Resources