- 1,235
- Posts
- 11
- Years
- Seen Jun 17, 2017
Programming languages are just that - languages. What seems illegible to someone would be perfectly understandable to another person.
For example, take the following simple C++ piece:
This is a simple command-line program that asks the user to input a fruit, and if their answer is either apple, orange, pear, grape or mango, the program will say such. If it is not any of those, the program will say "Unknown.".
While this might be simple, it could be difficult to make sense of for someone who does not know anything about programming, or even someone who does but does not understand this particular language (C++).
And that's one of the things I love about programming - what seemed like jibberish before all of a sudden makes sense when you learn it. And you can do so much.
---------
Anyway, what do you think of programming? Are you a programmer? What do you like about the language(s) you know? What do you not like?
And why does C++ not have switch statements for strings? I'm forced to use if-else chains to compare strings, unless I don't know the solution (I might not - I still only know the basics, haha).
For example, take the following simple C++ piece:
Spoiler:
Code:
[color=green]#include <iostream>[/color]
[color=purple]using namespace[/color] std;
[color=purple]enum[/color] Fruit
{
FRUIT_APPLE = 1,
FRUIT_ORANGE,
FRUIT_PEAR,
FRUIT_GRAPE,
FRUIT_MANGO
}
[color=purple]int[/color] fruitCheck(szFruit)
{
[color=purple]if[/color] (szFruit == "apple")
[color=purple]return[/color] 1;
[color=purple]else if[/color] (szFruit == "orange")
[color=purple]return[/color] 2;
[color=purple]else if[/color] (szFruit == "pear")
[color=purple]return[/color] 3;
[color=purple]else if[/color] (szFruit == "grape")
[color=purple]return[/color] 4;
[color=purple]else if[/color] (szFruit == "mango")
[color=purple]return[/color] 5;
[color=purple]else[/color]
[color=purple]return[/color] 0;
[color=purple]int[/color] main()
{
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Enter your favourite fruit type: "[/color];
[color=green]string[/color] szFruit;
[color=green]cin[/color] [color=red]>>[/color] szFruit;
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"\nYou entered: "[/color];
[color=purple]switch[/color] (fruitCheck(szFruit))
{
[color=purple]case[/color] FRUIT_APPLE:
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Apple."[/color] << [color=green]endl[/color];
[color=purple]case[/color] FRUIT_ORANGE:
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Orange."[/color] << [color=green]endl[/color];
[color=purple]case[/color] FRUIT_PEAR:
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Pear."[/color] << [color=green]endl[/color];
[color=purple]case[/color] FRUIT_GRAPE:
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Grape."[/color] << [color=green]endl[/color];
[color=purple]case[/color] FRUIT_MANGO:
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Mango."[/color] << [color=green]endl[/color];
[color=purple]default[/color]:
[color=green]cout[/color] [color=red]<<[/color] [color=blue]"Unknown."[/color] << [color=green]endl[/color];
}
[color=purple]return[/color] 0;
}
While this might be simple, it could be difficult to make sense of for someone who does not know anything about programming, or even someone who does but does not understand this particular language (C++).
And that's one of the things I love about programming - what seemed like jibberish before all of a sudden makes sense when you learn it. And you can do so much.
---------
Anyway, what do you think of programming? Are you a programmer? What do you like about the language(s) you know? What do you not like?
And why does C++ not have switch statements for strings? I'm forced to use if-else chains to compare strings, unless I don't know the solution (I might not - I still only know the basics, haha).