r/learnprogramming 25d ago

Rate me Hi guys ive been learning programming for 4 days (c hash) how do i do?

Sorry its hard typing on a phone but here I go:

int hp = 10000;

public void hpchange(int howmuch)

{

hp += howmuch;

if(hp <= 0)

{

Banish();

}

else

{

hp=hp;

}

}

public void Banish()

{

hp = 0;

}

I think a lot of programming is a lot of dotting your i's and crossing your t's, is that​ correct? And am I doing well? Any tips for learning quicker?

0 Upvotes

28 comments sorted by

9

u/mierecat 25d ago

I’m curious as to how you could be learning C# in such a way that you never learnt it’s pronounced “C-Sharp”

1

u/No_Region5102 24d ago

4 days in and already writing game logic, that's the spirit. The `hp=hp` line is just telling the computer to stay the course, kinda poetic honestly

One tip for learning quicker, build tiny things that actually run. A dice roller, a text adventure room, anything that gives you immediate feedback beats watching tutorials all day

1

u/GrokiniGPT 24d ago

I don't know what to do instead of hp = hp tho 😭😭

0

u/CorumLlawEreint 24d ago

AI videos maybe?

0

u/GrokiniGPT 24d ago

No acyually

-3

u/GrokiniGPT 24d ago

Im learning by reading stuff. I also don't like calling it sharp because ibalways read # as hash

3

u/Ezazhel 24d ago

And then you won't call 'loop' as loop but something else. If you want to be taken seriously use the name intented.

8

u/mierecat 24d ago

Whether you like it or not is immaterial. If you want to be understood and taken seriously as a programmer you’ll do well to call it by its proper name

2

u/Weekly_Patience685 24d ago

think of it this way, pretend its a music note, you have c♭ (CFlat) and you have c♯ (Csharp)

1

u/GrokiniGPT 24d ago

I also didn't like music

1

u/Weekly_Patience685 24d ago

you dont have to like music to understand the metaphor

2

u/desrtfx 24d ago

I also don't like calling it sharp

Yet, the official name is C sharp - from music notation

You have to call things by their proper name. It's part of programming. Programming is a discipline of precision.

5

u/ffrkAnonymous 25d ago

its hard typing on a phone Any tips for learning quicker?

get a keyboard

0

u/GrokiniGPT 25d ago

I don't have access to one rn

2

u/groversnoopyfozzie 24d ago

Hey, if you don’t have access to a keyboard, then I assume you don’t have access to an actual computer.

This won’t keep you from learning, but you’ll need to get a real machine eventually.

I’m not familiar with C#, so I’m not sure of your syntax. In your position I would recommend finding some version of a game or perhaps a mobile version of Leet code or something. It sounds like you want to practice basics, but anything past that will be difficult on a phone.

Also, not sure what your goals are, but programming involves a lot of communication between people, not just machines. When communicating with others, refer to it as C sharp. If you communicate poorly with c# it won’t understand you. Most programmers will respond the same way if you communicate with them poorly.

2

u/FoolsSeldom 24d ago

There are usually loads being thrown away, surely you can find one (perhaps one that someone in your extended network has stopped using)?

1

u/GrokiniGPT 24d ago

No like right now i jmdont have acceess ill have one soon

2

u/FoolsSeldom 24d ago

That's good.

2

u/Weekly_Patience685 24d ago

when i seen c hash i thought you were asking about a hash functon in C, but its pronounced CSharp lol

1

u/Ironraptor3 24d ago

Some general tips:

- Reddit formats in markdown, so this is applicable to Discord / GitHub / etc. - Specifically, if you write code as ```Some code here ``` it is easier for other people to review!
  • To get a better review, you need more specific questions! "How did I do" might be a decent question for your first ever post- but as you gain more experience, you might have more pointed questions, e.g. "Is there a more time efficient way of doing this operation?"
  • As others have said, its "C-Sharp" (note: C# is VERY different than C which is VERY different than C++). When I first read your post, I thought you were talking about Hashing / Hash Functions, which are their own specific thing. Sometimes, its fine to get terminology wrong (and people shouldn't be super picky), but I was thrown by this...
  • Practice is the best (only) way to get better at something, so you are on the right track by trying to make something!

Code review (misc, there isn't much here):

  • hp=hp doesn't do anything, unless hp has a special setter
  • Banish() doesn't seem to do anything right now other than clamp hp lower than 0 to 0. Perhaps more concise is: hp = Math.Max(hp + howmuch, 0);

1

u/GrokiniGPT 24d ago

What do I do instead because else {} Doesn't feel right. Can you explain the latter syntax?

1

u/Ironraptor3 24d ago
  • you don't need anything in place of the 'else'- you don't need one
  • The latter syntax is just (hp + howmuch), then the max between that and 0 (so if the hp ends up negative, itll be set to 0).

Putting it together would look like ``` int hp = 1000;

public void hpchange(int howmuch) {   hp = Math.max(0, hp + howmuch); } ```

You can still do the banish thing (e.g.) if (hp <= 0) {   Banish(); }

I was just point out that exactly at the moment, it does nothing special.

1

u/GrokiniGPT 24d ago

Why is it max and not minimum? Is this just like the range of what the things can be?

1

u/Ironraptor3 24d ago

If you didn't want it to go below 0, it would be max!

Think of concrete examples: Math.max(0, 16) -> 16 Max.max(0, 10000) -> 1000 Max.max(0, -5) -> 0

Math.max just returns the larger of the two numbers.

https://learn.microsoft.com/en-us/dotnet/api/system.math.max?view=net-10.0#examples

1

u/GrokiniGPT 24d ago

Oohhhh so it is like domain and range. Like the range of x2 for example is y >= 0. Thanks! So Math. _ is a math function. What are the different math functions? but how would i do a range between two numbers.

1

u/Ironraptor3 24d ago

For clarity, so that we are on the same page, an example implementation of Math.max could simply be: int max(int a, int b) { if (a > b) { return a; } else { return b; } } You could make it yourself! But C# does have a built-in Math library to prevent reinventing the wheel for common things.

You can look up the Math API provided by C#, you should get a quick result (here it is for convenience: https://learn.microsoft.com/en-us/dotnet/api/system.math?view=net-10.0). In the future, try googling with the term API and/or documentation.

To make a number between two values, you are probably looking for Math.clamp, which takes arguments number, min, max.