How do i change clion from camel case to snake case? - clion

I started using Clion a few days ago and im used to coding with snake case, but im getting constant suggestions from the IDE to change my variables to camel case. How do i turn that off?
int* pointer_vector_dinamico = new int [100]; //Pointer a vector dinamico.
IDE: Rename to "pointerVectorDinamico"

Related

I'm doing a course but the things the lecturer says works don't

I have recently gotten into programming and decided to learn C++. I took advantage of the sale on Udemy and bought three courses there, one for beginners on C++, one for game-making and one for Blender.
I started doing the course for beginners, the lecturer said that he would use Code::Blocks but that any other IDE would be fine so I downloaded Visual Studio 2017 because that's what the game-making course used. But when I do exactly as the lecturer says (and writes), the code won't compile correctly.
Here is an example:
What the lecturer wrote and got to work on his computer
#include <iostream>
using namespace std;
main()
{
cout << "Hello world! :-)";
}
What I figured out would work after some googling
#include <pch.h>
#include <iostream>
using std::cout;
int main()
{
cout << "Hello world! :-)";
}
And my question to those who are experienced is: What is the difference between Code::Blocks and Visual Studio 2017? What is different in that case? Will I even be able to use this course to learn?
Thanks in advance!
edit: edited in a missing # in the lecturer's code
#include <pch.h>:
See Gabriel's answer.
include <iostream> vs #include <iostream>:
The former is plain wrong. It has to be #include with the #.
using namespace std; vs using std::cout;:
While neither is particularly good practice, both should do the same thing here. If you write neither of them, you will have to write std::cout << ... instead of only cout << ... - that seems annoying but is something you should get used to if you want to eventually be a serious C++ programmer. See also Why is "using namespace std" considered bad practice?.
main() vs int main():
This is not something that Code::Blocks should allow because it is not correct C++. main should always return int.
Overall you seem to have hit an unfortunate number of differences between environments/compilers on this basic example already. However, neither your course nor VS2017 is wrong so far, so I recommend you keep using them. If something that your lecturer writes won't work for in a different environment, it's probably a bad idea to write that kind of code in the first place. And they did make several mistakes in this simple example.
PS: I strongly recommend enabling warnings, because they may tell you when you do something wrong in a more subtle way. There are many mistakes (of the "shooting yourself in the foot" kind) that the compiler is not required to stop you from making, but if you ask to be stopped (by heeding warnings) it will help you.
Using Visual Studio should be okay as long as you disable precompiled headers and your tutorial uses standard-compliant code.
About precompiled headers :
Visual Studio enables pre-compiled headers by default in a C++ command line program. This means that in your project, it'll by default force you to use a precompiled header in the first line of your source code (pch.h here).
By disabling them, you can almost* make the first snippet work in VS. To do this, select your project, go to the "Project->Properties" menu, then to the "Configuration Properties -> C/C++ -> Precompiled Headers" section, then change the "Precompiled Header" setting to "Not Using Precompiled Headers" option (this applies to VS 2012, applying this to other versions of VS should be easy).
If you want to avoid this in the future, you can create an empty project when setting up your project in VS.
See also : http://msdn.microsoft.com/en-us/library/h9x39eaw%28v=vs.71%29.aspx, How to avoid precompiled headers
* : The first snippet won't actually work since the declaration of main is not correct C++, only C (see https://en.cppreference.com/w/cpp/language/main_function, What is the proper declaration of main?)
To your actual question, VS will be fine for your course, although I'm still puzzled by the lecturer's original version of this code.
However, it's really useful to take the time to understand what all your changes did, and why they fixed your problem. Maybe you did this already - that's just not the impression I got from the phrase
What I figured out would work after some googling
when you get a compile error or warning, read it and try to understand it.
if you don't understand the error - and this is normal, certainly while you're learning - then hacking on the code until it works is perfectly fine. At least sometimes it's quicker, and the knowledge that you made progress is its own reward.
if hacking away at the code with the internet at your disposal doesn't get a solution, you'll just have to study the error message more. Turning all compiler errors and warnings on, and trying multiple compilers can both help - even if they all fail, the messages might be more useful. (I often find clang has useful errors, and godbolt.org is super helpful).
if hacking away at the code does get a solution, you should still try and understand why. Now you can see what you changed, look at the original error and try to understand why your changes fixed it. If you made multiple changes, were they all really necessary? Do you understand what they all did, and why?
If you do this, you can fix the next related problem faster, rather than going through the whole trial-and-error process again. You can even write better code that avoids the problem in the first place.
This is the part that actually constitutes learning, which is why I'm making a point of addressing it.
The important fix was changing the lines
include <iostream>
main()
to
#include <iostream>
int main()
because the former aren't legal C++. If your lecturer really wrote exactly that and you didn't somehow mis-copy, then I have no idea why their example worked.
The Visual Studio-specific stuff is the precompiled header, as described in Gabriel's answer.
But the remaining change is essentially cosmetic. Replacing:
using namespace std;
with
using std::cout;
Doesn't affect anything in your code, and just using
std::cout << "Hello world! :-)";
(with no using at all) would work just as well.

Code Error!? Why there is two different answer?

I have run a quite simple program in my pc but it's giving me the wrong answer. When I copied the code to an online IDE, the answer is correct. I am using CodeBlocks. Where is the problem.?
Online IDE link: https://ideone.com/yKV5NV
This is the image of the result in my PC:
My Code:
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
int x=5,k=2,ans;
ans=(pow(x,k+1));
printf("%d",ans);
return 0;
}
PS: I think maybe because of the double data type rounding error. But why it is happening everytime. If I am right, how to fix it?
I think it could be because of floating point number representation that can't hold "exact" value that you expect. It happens every time because of same input data, so why wouldn't it? Regarding how to fix it, there is nothing to fix really, it's simply the way floating point numbers are working.

Swift XCode getting internal errors when using enums

When using dot notation for enums using Swift, I always get internal errors (XCode kind of crashes)
For example
enum WeatherData {
case current, forecast, forecastTenDay, yesterday
}
let dataType: WeatherData = .current
As soon as I type in the period, it all goes weird.
No syntax coloring temporarily, and although it recovers, it's really annoying.
I use MacBook Pro (Retina, Mid 2012).
Anyone else getting this error?

Can a IDE find logic errors?

Can a good IDE (e.g. Visual Studio) find basic logic errors?
or is there no such thing as a "basic" logic error and all of these errors are undetectable by the IDE?
Yes, some IDEs (like Visual Studio) have continous syntax checks, that can find some logical errors. However, a logical error can only be spotted if there is something odd in the code, there is no AI trying to figure out what the code is actually intended to do.
If you for example write this in a C# method in Visual Studio:
int a = 1;
int b = 2;
Console.WriteLine(a + a);
then the IDE will notice that you never used the variable b, and put a warning in the form of a squiggly line under the variable. Pointing on it will reveal the message The variable 'b' is assigned, but its value is never used.
The IDE can't know if you intended to output a + b rather than a + a, and simply the use of a + a is not odd enough to render a warning, but it can see that you created a variable b and that you probably intended to use that for something.
Not really.
Sometimes it can pick up that a code path may never execute I think.
int x = 9;
if (x != 9)
{
foo();
}
and it maybe able to tell you that you've declared something without using it. It's stuff you can catch yourself. However, the real power is in the debugger where you can use "watch" or locals/autos and follow the code with step-in/out/over at any scope, see when they change, and change the values yourself to see what needs to happen. It's a good way to test logic. In assembly, you can move your code back a few lines and repeat it... it's not guaranteed to work, but you can override anything.
Edit: see https://en.wikipedia.org/wiki/Halting_problem

taking the address of temporary object

I'm developping on many platforms, today I have a problem with iOS and xCode,
I'm upadating some projects to the last xCode 4.3.2 (Apple LLVM compiler 3.1)
since few time a warning has become an error: "taking the address of temporary object"
unfortunately I used many of that, see my example :
float dist = Vector3Dlength(&Vector3D(pos2 - pos1));
to avoid to create a temporary var and produce a new line of code (although this one is created on the stack by the compiler)
I know the mistakes that can lead since 10 years of coding like that :) but I WANT to continue like that...
someone have a suggestion to avoid this error without having to edit the code ? (with the new xCode 4.3.2 (Apple LLVM compiler 3.1))
You'll need to change your code, you can't take an address of something that is not an lvalue, and that temporary isn't one.
Change your code to take a const reference to Vector3D instead. This will not cost you a copy, and is well-defined behavior.
float Vector3Dlength(Vector3D const& pvect) {
return sqrt(pvect.x * pvect.x ...);
}
...
float dist = Vector3Dlength(Vector3D(pos2 - pos1));

Resources