Need advice about which tool to choose?Ask the StackShare community!
C++ vs Scala: What are the differences?
Introduction
C++ and Scala are two popular programming languages commonly used for different software development purposes. While C++ is a statically-typed, compiled language that is widely used for systems programming and game development, Scala is a statically-typed, JVM-based language mainly used for building scalable applications. Although both languages have similarities, they also have key differences that set them apart. In the following paragraphs, we will explore some of the major differences between C++ and Scala.
Syntax and Expressiveness: C++ has a more verbose and complex syntax compared to Scala. C++ code tends to be longer and require more boilerplate code for common tasks. On the other hand, Scala has a more concise and expressive syntax, allowing developers to write cleaner code and achieve more functionality with fewer lines of code.
Object-oriented vs. Functional programming: While both C++ and Scala support object-oriented programming (OOP), Scala also includes strong functional programming (FP) capabilities. Scala has first-class functions, immutability by default, and supports higher-order functions, pattern matching, and functional composition. C++ focuses primarily on OOP and procedural programming, but it also supports some FP concepts through libraries like the Standard Template Library (STL) and lambda expressions introduced in C++11.
Memory Management: In C++, memory management is done manually by the developer using constructs like pointers, new and delete operators, and smart pointers. This gives the developer fine-grained control over memory allocation and deallocation, but it also introduces the risk of memory leaks and segmentation faults if not handled properly. In contrast, Scala uses automatic memory management through a garbage collector, relieving the developer from the burden of explicit memory management.
Concurrency and Parallelism: C++ provides low-level support for concurrency through features like threads, mutexes, and condition variables. However, managing concurrent code in C++ can be complex and error-prone. Scala, on the other hand, provides higher-level abstractions for concurrency and parallelism, such as actors and the Akka toolkit. These abstractions make it easier to write concurrent and parallel code by handling the complexities of thread synchronization and message passing.
Type System: C++ has a strong and static type system that requires explicit type annotations and supports explicit type casts. This can be beneficial for performance and fine-grained control over memory layout. However, it can also make the code more verbose and prone to type-related errors. Scala, with its static type system, provides type inference, which can reduce the need for explicit type annotations while still ensuring type safety.
Ecosystem and Tooling: C++ has a mature ecosystem with a wide range of libraries, frameworks, and tools available for various domains, such as game development, embedded systems, and high-performance computing. It also has a comprehensive build system, like CMake. Scala, being based on the Java Virtual Machine (JVM), benefits from the rich Java ecosystem, including libraries like Apache Spark for big data processing and Play Framework for web development. It also has robust build tools like sbt and a powerful IDE support with IntelliJ IDEA and Scala-specific plugins.
In summary, C++ and Scala differ in terms of syntax, programming paradigms, memory management, concurrency models, type systems, and ecosystem/tooling. While C++ is known for its performance, control, and low-level capabilities, Scala offers expressiveness, conciseness, and higher-level abstractions for concurrency and functional programming. The choice between the two languages depends on the specific requirements of the project and the developers' preferences.
I will use Elixir for personal projects. It's productive, reliable, secure, simple, etc. But when performance is critical, I need job opportunities, when I work with mutability, which do I pick? I need advice on which "bureaucratic, mainstream" programming language to pick when wanting performance and jobs. Elixir is often "slow", and it hasn't boomed yet the way Golang and Rust have, so which?
Well for those performant tasks maybe you can use Rust nifs for elixir. Elixir enables to write fault-tolerant, scalable code for concurrent systems, and as such, it is perfect for messaging systems and web applications that might need to handle a lot of users efficiently. But if you need speed you can plug in Rust or write a microservice using Goland/Rust.
Basically, I am looking for a good language that compiles to Java and JavaScript(and can use their libraries/frameworks). These JVM languages seem good to me, but I have no interest in Android. Which programming language is the best of these? I am looking for one with high money and something functional.
Edit: Kotlin was originally on this list but I removed it since I had no interest in Android
Clojure is a Lisp dialect, so if you like Lisp that's probably the way to go. Scala is more popular and broadly used, and has a larger job market especially for data engineering. Both are functional but Scala is more interoperable with Java libraries, probably a big factor in its popularity. I prefer Scala for a number of reasons, but in terms of jobs Scala is the clear leader.
Scala has more momentum. It is good for back-end programming. The popular big data framework Spark is written in Scala. Spark is a marketable skill.
If you need to program something very dynamic like old school A.I., Clojure is attractive. You would chose Scala if prefer a statically typed language, and Clojure if you prefer a dynamically typed language.
It's not clear exactly what you mean by "high money", you mean financial support to the language, money paid for a job, economic health of the market the language is positioned on?
In any case, it's very hard to give any advice here, since you'd need to provide details on the intended usage, what sector, kind of product/service, team size, potential customer type... Both languages are very general purpose and decently supported, each have its own pros and cons, both are functional as approach, and neither is really mainstream.
include include int main(){ char name[10], pasword[10]; printf("enter you user name :"); gets(name); printf("enter your pasword : "); gets(pasword); printf("your name : %s \n your password : %s \n", name, pasword); if ( name != "youcef") { printf("name undefined\n"); } else { printf("finde name"); }
}
his not working
You will want to do a few things here. First, replace gets
with fgets
. Then, you're going to want to use strcmp
from string.h to compare the input with the desired result. The code listed below has been updated with a working example with the previously mentioned recommendations. This isn't perfect and there are other ways to accomplish the same task. Explore other options that are available when you have a chance and see if you can improve on this example.
#include <stdio.h>
#include <string.h>
int main()
{
char name[10],
pasword[10];
printf("enter you user name :");
// Use fgets as gets is insecure and can easily lead to buffer overflow exploits
fgets(name, sizeof(char) * sizeof(name), stdin);
// Remove \n from fgets stdin read with null character so as to not have to include
// in strcmp later.
name[strlen(name) - 1] = '\0';
printf("enter your pasword : ");
fgets(pasword, sizeof(char) * sizeof(pasword), stdin);
printf("your name : %s \n your password : %s \n", name, pasword);
// If strcmp result > 0 || < 0 it's not a match
if (strcmp(name, "youcef") != 0)
{
printf("name undefined\n");
}
else
{
printf("finde name");
}
}
Dear, Yusuf You can't use if statement to compare two strings, but you can use strcmp() function which means string compare The behavior of strcmp function is: If (string1 < string2)? Then: return a negative value. If (string1 > string2)? Then: return a positive value.
If(string1 == string2)? Then: return (0).So, you can modify this statment to: if(strcmp(name,"Yousef") != 0) printf("name undefined\n");
else printf("find name");But, In this case there is one logic problem that (strcmp) function don't ignore the letter case. For example: If you input name : yousef
The first letter here (y) is small, but in the comparing statement above is capital, So the result will be "name undefined", but in fact "yousef" = "Yousef".To solve this problem you should use stracasecmp() function. This function ignore the letter case while comparing. The code will be: if(strcasecmp(name,"Yousef") != 0) printf("name undefined\n");
else printf("find name");Attention: Include string libreary after using these functions to skip any problem may be found.
includemay Allah bless you ^_^
Hello, I am interested in learning how to program. I am a beginner, and many articles saying I should go with Python if I am new to programming. I considered Lua a long time ago, but for my career, I believe major programming languages should be better for me. I'm considering Python at this moment, but if you have other tools I should use, let me know.
Although Lua is a very simple,efficient, elegant and welcoming language, Python is extremely versatile. Therefore, if you want to get into programming without a defined direction, Python is the way to go. It has a lot of libraries, the ability to do anything and it is closer to other languages than Lua is (yeah I know about Lua and C, but from a learner's point of view, it makes sense). Additionally, Python will be a marketable skill, but I for one have not yet seen job offers for Lua devs.
The language you choose is also dependant on the type of career / area of programming you wish to focus on: Web Based and mobile applicaitons I would lean towards Java, PC Applications I tend to like C#, Embedded industry C, C++
my advice , you should answer me for this question, what do you like to work: web base or mobile native or cross platform. if you like web base you should choose PHP or ASP.net or Node.js or if you like mobile native you should decide Android or IOS platform and else if you like cross platfrom you should learn Flutter with dart language. thanks
Hi, I'm just starting to learn code, and I stumbled upon this website. I think I should learn JavaScript, Python, and C++ to begin with. I'm a quick learner so I am only worried about what would be more useful. Suppose my goal is to build an online clothing store or something. Then what languages would be best? I need advice. Please help me out. I'm 13 and just beginning and it's hard to understand when people use technical terms so please keep it simple. Thanks a lot.
Go with Python. It's syntax is really simple and less verbose compare to others. You can use Python for basically anything like web dev, task automation, data science, data engineering, cybersecurity etc. At initial level, it's more important to get an understanding of programming fundamentals. Once you get conformable with coding in general, then you can explore other languages.
I would worry less about languages when you're first starting out. If you want to build an online store, then javascript is a great language that is used all over the web! Get comfortable with your first language, learn some computer science concepts and how to build things the right way, and then just work towards a goal and learn as you go!
https://www.w3schools.com/ is a great resource and it's completely free, everything you need to know to build a website is on that page if you have the drive to learn it. Best of luck to you!
Here's a neat roadmap too, in case you find yourself lost on what to learn next https://roadmap.sh/frontend
I recommend JavaScript to build your first website, for both FrontEnd and BackEnd , even tho I am a BIG fan of C++ it is not well suited yet to create websites, and Python would be just as good for the BackEnd as JavaScript but having everything written in only one language will make your learning curve way easier, so it is easy to recommend JavaScript.
Python is an easy and beginner-friendly language. As you've mentioned about Online Clothing store, you'll need to deal with the website part and you'll need Javascript to make the site accessible and functional. Javascript will be more easy to learn if you learn Python first, so you can just start with Python.
Hello Rachel, as a fellow programmer, I am glad that you are planning on expanding your coding knowledge and skills.
I recommend learning python first as it has a very simple syntax (syntax is how your code looks and how simple it is to type) and is also very user-friendly. Once you get to know how to code in python, you can use this thing called Flask.
Flask is what you call a "web application framework" or a WAF, it basically is a tool used to develop websites and other similar things. You don't have to worry much about it's difficulty because it is based on python. You will still have to learn how to use Flask though as it could be a bit complicating in first glance.If you are looking for simpler ways for making website without having to learn a lot of programming, you can learn HTML and CSS. These 2 will help you in making a basic and functional website. The catch is, from a career perspective, HTML won't get you far, as literally every programmer knows it. So it is best to use programming languages.
I hope this gave you a clear understanding of the ways in which you can build websites. Wishing you the best of luck!
I have worked with all these a ton. I make ecommerce and enterprise apps now. The only one of these you need is JavaScript. You can use JS on the backend as Node.js in AWS Lambda. You will need HTML and CSS skills, as well as a database. I recommend MongoDB. Please forget about C++ until you built your first company. Python fits the same purpose as Node.js but is currently popular in the Data Science community so skip it until you have a LOT of customers.
Since you're new, I'd recommend Javascript and Python. With Javascript, just learn React and Node. And with Python, learn Django. With JavaScript, Node, React, Python, and Django; you can accomplish quite a lot for both frontend and backend.
Hi, When saying that "Suppose my goal is to build an online clothing store or something", I would go for a ready to use platform like Wordpress. it will give you a fast jump into the online world. By using WP you'll have to catch on with PHP\JQuery Goodluck.. Ping me when store is ready, I might buy something....
Finding the best server-side tool for building a personal information organizer that focuses on performance, simplicity, and scalability.
performance and scalability get a prototype going fast by keeping codebase simple find hosting that is affordable and scales well (Java/Scala-based ones might not be affordable)
I've picked Node.js here but honestly it's a toss up between that and Go around this. It really depends on your background and skillset around "get something going fast" for one of these languages. Based on not knowing that I've suggested Node because it can be easier to prototype quickly and built right is performant enough. The scaffolding provided around Node.js services (Koa, Restify, NestJS) means you can get up and running pretty easily. It's important to note that the tooling surrounding this is good also, such as tracing, metrics et al (important when you're building production ready services).
You'll get more scalability and perf from go, but balancing them out I would say that you'll get pretty far with a well built Node.JS service (our entire site with over 1.5k requests/m scales easily and holds it's own with 4 pods in production.
Without knowing the scale you are building for and the systems you are using around it it's hard to say for certain this is the right route.
We're moving from Java to Kotlin with our Microservice Stack (Spring Boot) because it is excellently supported by framework and tools and the learning curve is not very steep Kotlin is way more straightforward and convenient to use while providing less boilerplate and more strictness, which finally leads to better code, which is more readable, maintainable and less error-prone. We especially like Kotlin's (functional) data structures, which are, e.g. compared to Scala, easier to understand and don't require deep knowledge in functional programming.
I had a goal to create the simplest accounting software for Mac and Windows to help small businesses in Canada.
This led me to a long 2 years of exploration of the best language that could provide these features:
- Great overall productivity
- International wide-spread usage for long-term sustainability and easy to find documentation
- Versatility for creating websites and desktop softwares
- Enjoyable developper experience
- Ability to create good looking modern UIs
- Job openings with this language
I tried Python, Java, C# and C++ without finding what I was looking for.
When I discovered Javascript, I really knew it was the right language to use. Thinking of this today makes me realize even more how great a decision this has been to learn, use and master Javascript. It has been a fun, challenging and productive road on which I am still satisfied.
Obviously, when I refer to Javascript, it is not without implying the vast ecosystem around it. For me, JS is a whole universe in which almost every imaginable tools exist. It's awesome - for real. Thanks to all the contributors which have made it possible.
To be even clearer about how intense I am with Javascript, let's just say that my first passion was music. Until, I find coding with Javascript! Yep, I know!
So in conclusion, I chose Javascript because it is versatile, enjoyable, widely used, productive for both desktop softwares and websites with ability to create modern great looking user interfaces (assuming HTML and CSS are involved) and finally there are job openings.
Python has become the most popular language for machine learning right now since almost all machine learning tools provide service for this language, and it is really to use since it has many build-in objects like Hashtable. In C, you need to implement everything by yourself.
C++ is one of the most popular programming languages in graphics. It has many fancy libraries like eigen to help us process matrix. I have many previous projects about graphics based on C++ and this time, we also need to deal with graphics since we need to analyze movements of the human body. C++ has much more advantages than Java. C++ uses only compiler, whereas Java uses compiler and interpreter in both. C++ supports both operator overloading and method overloading whereas Java only supports method overloading. C++ supports manual object management with the help of new and delete keywords whereas Java has built-in automatic garbage collection.
I am working in the domain of big data and machine learning. I am helping companies with bringing their machine learning models to the production. In many projects there is a tendency to port Python, PySpark code to Scala and Scala Spark.
This yields to longer time to market and a lot of mistakes due to necessity to understand and re-write the code. Also many libraries/apis that data scientists/machine learning practitioners use are not available in jvm ecosystem.
Simply, refactoring (if necessary) and organising the code of the data scientists by following best practices of software development is less error prone and faster comparing to re-write in Scala.
Pipeline orchestration tools such as Luigi/Airflow is python native and fits well to this picture.
I have heard some arguments against Python such as, it is slow, or it is hard to maintain due to its dynamically typed language. However cost/benefit of time consumed porting python code to java/scala alone would be enough as a counter-argument. ML pipelines rarerly contains a lot of code (if that is not the case, such as complex domain and significant amount of code, then scala would be a better fit).
In terms of performance, I did not see any issues with Python. It is not the fastest runtime around but ML applications are rarely time-critical (majority of them is batch based).
I still prefer Scala for developing APIs and for applications where the domain contains complex logic.
We needed to incorporate Big Data Framework for data stream analysis, specifically Apache Spark / Apache Storm. The three options of languages were most suitable for the job - Python, Java, Scala.
The winner was Python for the top of the class, high-performance data analysis libraries (NumPy, Pandas) written in C, quick learning curve, quick prototyping allowance, and a great connection with other future tools for machine learning as Tensorflow.
The whole code was shorter & more readable which made it easier to develop and maintain.
As a personal research project I wanted to add post-quantum crypto KEM (key encapsulation) algorithms and new symmetric crypto session algorithms to openssh. I found the openssh code and its channel/context management extremely complex.
Concurrently, I was learning Go. It occurred to me that Go's excellent standard library, including crypto libraries, plus its much safer memory model and string/buffer handling would be better suited to a secure remote shell solution. So I started from scratch, writing a clean-room Go-based solution, without regard for ssh compatibility. Interactive and token-based login, secure copy and tunnels.
Of course, it needs a proper security audit for side channel attacks, protocol vulnerabilities and so on -- but I was impressed by how much simpler a client-server application with crypto and complex terminal handling was in Go.
$ sloc openssh-portable Languages Files Code Comment Blank Total CodeLns Total 502 112982 14327 15705 143014 100.0% C 389 105938 13349 14416 133703 93.5% Shell 92 6118 937 1129 8184 5.7% Make 16 468 37 131 636 0.4% AWK 1 363 0 7 370 0.3% C++ 3 79 4 18 101 0.1% Conf 1 16 0 4 20 0.0% $ sloc xs Languages Files Code Comment Blank Total CodeLns Total 34 3658 1231 655 5544 100.0% Go 19 3230 1199 507 4936 89.0% Markdown 2 181 0 76 257 4.6% Make 7 148 4 50 202 3.6% YAML 1 39 0 5 44 0.8% Text 1 30 0 7 37 0.7% Modula 1 16 0 2 18 0.3% Shell 3 14 28 8 50 0.9%
Pros of C++
- Performance202
- Control over memory allocation107
- Cross-platform98
- Fast97
- Object oriented84
- Industry standard58
- Smart pointers47
- Templates37
- Gui toolkits16
- Raii16
- Generic programming13
- Control13
- Flexibility13
- Metaprogramming11
- Hardcore9
- Many large libraries5
- Simple5
- Full-fledged containers/collections API5
- Large number of Libraries4
- Performant multi-paradigm language4
- Way too complicated3
- Close to Reality1
- Plenty of useful features1
Pros of Scala
- Static typing188
- Pattern-matching178
- Jvm175
- Scala is fun172
- Types138
- Concurrency95
- Actor library88
- Solve functional problems86
- Open source81
- Solve concurrency in a safer way80
- Functional44
- Fast24
- Generics23
- It makes me a better engineer18
- Syntactic sugar17
- Scalable13
- First-class functions10
- Type safety10
- Interactive REPL9
- Expressive8
- SBT7
- Case classes6
- Implicit parameters6
- Rapid and Safe Development using Functional Programming4
- JVM, OOP and Functional programming, and static typing4
- Object-oriented4
- Used by Twitter4
- Functional Proframming3
- Spark2
- Beautiful Code2
- Safety2
- Growing Community2
- DSL1
- Rich Static Types System and great Concurrency support1
- Naturally enforce high code quality1
- Akka Streams1
- Akka1
- Reactive Streams1
- Easy embedded DSLs1
- Mill build tool1
- Freedom to choose the right tools for a job0
Sign up to add or upvote prosMake informed product decisions
Cons of C++
- Slow compilation8
- Unsafe8
- Over-complicated6
- Fragile ABI6
- No standard/mainstream dependency management5
- Templates mess with compilation units4
- Too low level for most tasks3
- Compile time features are a mess1
- Template metaprogramming is insane1
- Segfaults1
- Unreal engine1
Cons of Scala
- Slow compilation time11
- Multiple ropes and styles to hang your self7
- Too few developers available6
- Complicated subtyping4
- My coworkers using scala are racist against other stuff2