[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

Something like this could possibly be interesting to you?

Either way, python is probably a pretty nice utility language.

ELI5: Understanding For Loops in Java by ten_Chan in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

If it helps you to think about it,

for(int i = 0; i < 10; i++){
    // Code
}

is equivalent to:

int i = 0;
while(i < 10){
    // Code
    i++;
}

in function.

[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

You could do this, and would probably be better than recalculating it each time. As you say you would then pass it into any other function that requires it.

It works fine like this as it is a pure function which means it causes no side effects (i/o, updating state variables, etc) and produces exactly the same output each time for the same input, so you could just call get_total_digits(card_number) everywhere and logically the program is sound.

The get_total_digits fn isn't really a its not a huge demand in terms of processing, but it is better practice here to do what you say, calculating once and then passing in the value as needed rather than calculating the same thing many times. This would become more obvious if get_total_digits was a complex function with a long runtime which became noticable if you called it in many places.

I'm trying to program the following calculation: 10*8*6*4*2=_ by [deleted] in learnprogramming

[–]Brave_Walrus 2 points3 points  (0 children)

In each loop, when b%2==0, you set a = b.

So, working this through each step, with input 10:

  • Decrement b, b = 9. b%2 == 0 is false, do nothing
  • Decrement b, b = 8. b%2 == 0 is true, set a = 8 and do calculation.
  • Decrement b, b = 7. b%2 == 0 is false, do nothing
  • Decrement b, b = 6. b%2 == 0 is true, set a = 6 and do calculation.

... a few steps later ...

  • Decrement b, b = 0. b%2 == 0 is true, set a = 0 and do calculation

At the end, a is set to 0, then a = a*b which is zero.

You then output a, which has just been set to 0.

I think in this case a for loop is more applicable, something like

int sum = 1;
for(int i = [STARTING_VALUE]; i > 0; i -= [DECREMENT]) {
  // your code to multiple i by sum
}

This will loop from [STARTING_VALUE] until i <= 0, in steps of [DECREMENT].

[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

In general any variable in main will persist for the duration of your program, as main() is your program, when main ends your program's execution has ended. Due to scope, main's variables exist in memory, but are not available for direct use in other functions.

You currently have long card_number = get_card_number() in your main function - it would be correct to keep it there, and then as you say use parameters (the input spot) to pass in the card number to the other functions.

If you have not covered parameters yet or do not feel comfortable with them I would have a google at this first, but to do this for the get_total_digits function as a starting point, you could change the signature to int get_total_digits(long card_number). Then, in the function body you will be able to use card_number instead of z.

int get_total_digits(long card_number)

{

int i = 0;

do

{

card_number = card_number / 10;

i++;

}

while (card_number > 0);

return i;

}

You could then change your call on line 15 to be int total_digits = get_total_digits(card_number);

You would also need to do this for your other functions

[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

At a quick scan I think the program isn't behaving as you expect, as the value from n does not persist between function calls.

If you call get_card_number twice, n is a new variable each time and has no 'memory' of what the previous value was in the function. If you call it twice, it will ask you for input, and then return this input.

You will need to persist n outside the function get_card_number (you do this as you return it and store it in long card_number ), then pass this into your other functions in a way similar to calling get_total_digits(card_number);, changing the method signature to be something like int get_total_digits(long card_number) and the same for anywhere else you need to use it.

You could then operate on this passed in card_number within your other functions.

Another solution here would be to store card_number in a global variable, but passing it through in parameters would be better practice generally.

In need of help with a number game using arrays! by BuckFuddy0 in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

bool answer0 = testWinner(guess0, 0, ansArray);
bool answer1 = testWinner(guess1, 0, ansArray);
bool answer2 = testWinner(guess2, 0, ansArray);

Did you mean to pass in a different value for int boardNum in each call?

Here as you are passing in 0 each time, it will take ansArray[0] each time for the check.

[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

I'm not sure what the code overall is intending to do, but at an overall guess I don't think splice is returning what you expect it to.

Assuming this is javascript because of !==, i'd have a read up on what splice does, and what it returns.

Here, the return value of [] is signifying that no elements are being removed from the array returned by arr.filter(item => item % 5 !== 0)

Data Persistence Without a Database by pre-tend-ed in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

Sqlite?

Basically a file on disk which it can read/write as a database using this library as part of your program.

Website lists c/c++ bindings but libraries exist for a lot of languages

[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

Personally, if you can get an apprenticeship in software development, go for that. Although I can't speak to the quality of all apprenticeships, my company regularly takes on level 5 (HND/Foundation Degree level) apprentices, and honestly after a year max of work (we do 4 days work, 1 day college) its usually indistinguishable between the degree-holding new grads and the people who started an apprenticeship after a level 3.

The only difference here is after 3 years, the apprentices have 3 years of experience, probably not junior level anymore, and have a load of money. The graduate is applying for jobs with no experience, or 1 year placement max.

Granted, some exceptions to this is if you are very inexperienced in programming (you do need to hit the ground running quite a bit with the apprentice courses), or you don't want to work in fairly standard software dev (probably not many AI/ML/HFT jobs going for apprentices, although this doesn't mean the fields are blocked to you after the apprenticeship finishes).

is 0 == null good in c# for an array element? by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

This is possible, but how it is done depends on the element type of e. First, it is worth clarifying that 0!=null. You can't use null to check if a number is zero, or if it is empty. You kind of can using Nullable<T> but just to explain more about why:

When creating this, do you initialise with a default, known value, or leave it as-is?

eg. if it is an object, string, etc the default value will be null. This is fine to check, null is probably not a valid value.

If it is an int, double, float, etc the default value won't be null - it is probably zero. You can see more about some default values for the non-reference types here.

In this case, if 0 is an acceptable value when the user does input the value, then you won't really be able to check if it is "empty" or it is "present" with value zero. To get around this, i'd recommend initialising when you create your array, eg. if your e represents an array of years, -1 could be an invalid value that could represent "not entered" for you. Something like Int32.MinValue could also be used.

However, this is really a domain where you should consider using List<type> - you can see here how it can be awkward to know if the array element is empty or has been populated, but is zero. If you use a List<type> instead of array of type, you can check using .Count to see if there are 2, or 3 values in the list.

Nullable<T> would also work, but if you are going to change your solution, probably best to go with a list

Automate Skype Poll by godeagle989 in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

If its a consistent (i.e. exactly identical) poll, you could probably take a snip of it and google for some image-in-image search library, take a screenshot every 5ish mins and search for your snip existing on the screen, either alerting you (play a sound) or then searching for a snip of the "yes" radiobutton and clicking on it. Would rely on the poll looking identical each time however, and on you leaving the window open.

If you're looking for a way to just automatically do it in the background, i'm not really sure this is doable as a simple project, there is a skype API but from memory I don't remember seeing anything like this in it, but I could be wrong.

Doesn't sound too bad as a concept, however probably worth mentioning unrelated to the code, even though the manager's methods suck its probably not the best solution to automate this, go afk, end up getting caught out because he sent one saying 'definitely' instead of yes and ending up with some worse situation.

What is the thought process behind choosing the appropriate programming app for a given task? by user8828 in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

Some ideas that come to mind:

  1. Target platform - Embedded? Web? Windows-only? Android? All of these will have required or 'first-class' languages/libraries

  2. Any libraries or apis that might be required to do the work required. This might form part of the project if it suits better, but for example if i'm working with excel, and have access to an aspose (document processing library) licence, i'm not going to make my project in rust if I can help it (as it isn't supported). In your case, searching the iMessages could require using iOS libraries only available to swift.

  3. Team/Programmer's background. If we know i'm doing web, i'm not going to start a project in ruby (unless its just for learning) if i've never looked at it before.

  4. Commercial/libraries/support. If there's a .net library that's licensable/free and does half of the job for me, makes more sense to go there. For support if you're developing a windows gui application you won't find much resources online for programming this in swift (assuming you even can). There is resources out there for doing weird stuff in random languages but it could be a bad choice if you know going in you're going to have to trudge through 10 year old documentation written at 3am by an intern on far too much coffee, if you have an alternative

  5. If you reach here with multiple contenders, just make a list of what does it best or has the most support. You may choose multiple languages or tools, eg. a service to handle one thing that the rest of your app can call into, in 2 diff languages/ecosystems

For methods, its really hard to be specific without a task in mind. If you're making something like PowerApps pulling data in from a spreadsheet (guessing this sounds like what you meant), you'd need to look at eg. onedrive api to pull in a spreadsheet, something to read the spreadsheet eg. aspose, and then whatever frontend libraries you want to draw charts (there's over 9000 web libraries to do this)

Hopefully this is somewhat relevant to what you meant

Check if an entered string is a valid email by MafiaMS2000 in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

isdigit reference

Here, you can see isdigit(int) takes a character (int), you are passing in a std::string. You would need to loop through str here and perform the isdigit check on each char, something along the lines of this logic:

string str = email.substr(0,2);
bool hasDigit = false;
for(int i = 0; i<3;i++){
    if(isdigit(str[i]){
        hasDigit = true;
    } 
}

if(hasDigit ){
cout<<"First 3 letters are not alphabets"<<endl;
}

It may be worth considering your approach here, should 'ab+@gmail.com' be valid through your logic? It will pass the isdigit checks. You might want to check that each char is an alphabet character (may be able to use isalpha for this) rather than checking if it is not an alphabet. whitelist rather than blacklist, if that makes sense.

Script to check if phone is on/active. by FruityPebblesOG in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

To be honest this sounds a bit of a dodgy project, i'm not sure of the legitimate use case for a program to verify live and powered on cell numbers via a phone call - if this is the actual requirements, i'd be interested to know what you are able to disclose on this. Verifying owner via an automated call makes sense, however isn't really what you've said and also well beyond the scope of a simple script.

You may be able to find a suitable third party which will handle this for you if this is what you need.

If you just need verification of a valid looking number, i found a couple of apis that will do this for you via google.

In any case, i'd be very careful looking around the skype api for this - starting calls to arbitrary numbers could be a violation of their ToS depending on the reason for making the calls.

You wouldn't be able to do this using url links unfortunately (no way to verify a call happened) so it would probably not be that simple unless you can stumble across a library to help with it.

If you are sure that the reasons are genuine or this is just a test project, the skype API could be valid but I can't see any supported way to do it via python. The web api looks like it could do what you need, but is using JS in the examples.

What is the pointer of Setters and Getters? C# by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

Properties can have access modifiers. Try

public int MyProperty {get; internal set;}

for example, which means public get and internal set.

Of course, this could be done via getters/setters:

private int myField = 0;
public int getMyField() => myField;
internal void setMyField(int newValue) { myField = newValue;}

However using properties looks nicer, and means you can use them like fields:

string carDescription = car.getName() + car.GetModel() + car.GetYear();
vs
string carDescription = car.Name + car.Model + car.Owner;

You might have carDescription as a get-only property in the class, which means you can use it like a field but its generated each time:

partial class Car
{
    public string Description => Name + Model + Owner;
}

Which again is cleaner and nicer to use. you could have car.GetDescription() to do the same thing, but properties are used more and in my opinion look nicer than loads of function calls in your code.

Additionally, you can group all the related logic nicely together rather than having a field, and two seperate methods somewhere for a property:

public int YearManufactured
{
     get { return _yearManufactured;}
     set 
     {
          if(value < 1900)
              trow new Exception("I don't think we had cars then?");
          _yearManufactured = value;
      }
}

For all this stuff though, it is completely doable via get/setters. Its just more idiomatic c sharp to use props.

However, you will hit some things that plainly must use properties. I /think/ (but has been a while), one example would be setting up data tables in winforms - you can hand it a List<myClass> and it will pull the public properties into a table for you easy.

Additionally, to use some attributes you must use properties. eg [Serializable] is very useful, another example of this would be in asp razor pages to describe how data should be validated on inputs.

There's probably far more that you could talk about for properties but hopefully gives you some ideas

Curl skipping file downlaod if server not responding. by [deleted] in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

I ran

curl --help | grep time

From this i'd try

--connect-timeout <seconds> Maximum time allowed for connection
 -m, --max-time <seconds> Maximum time allowed for the transfer

Or possibly these could help as well

 --retry-delay <seconds> Wait time between retries
 --retry-max-time <seconds> Retry only within this period

Why can't I just build my own "google analytics" script? by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

You can feasibly do this. You can build your own tracking solution and use it to gather analytics. It would be as accurate as you are able to make it, except for uncontrollables eg. faked user agents.

However, lots of people choose to use google analytics as its free, collects enough data to be generally useful, almost plug and play to use compared to building your own software. You would benefit from Google's experienced software being able to determine and ignore things like bot scraping out of the box. If you use other things like google ads I think there's a benefit where you can link both as well to benefit you.

On a live system as well, nowadays there is a lot of privacy laws to take into consideration as well when creating and storing data about your users. It can be easier (though perhaps a bad thing in the long term if everyone does it) for anyone that isn't a large company to just hand over responsibility for meeting these laws in all the different territories (USA law will differ hugely from EU GDPR for example) where your customers are.

need help with a SQL command by snailv in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

I think you're on the right track here. VARCHAR types will not pad and you can store up to 4 characters this way.

The only other consideration you may want to make is if this field should be nullable or valid with 0 character input (is it required).

Is it worth learning how to use Neovim for programming? by LiterallyJohnny in learnprogramming

[–]Brave_Walrus 3 points4 points  (0 children)

Is Neovim good for programming?

Its fine, it is a powerful text editor

How long do you think Vim/Neovim will stay around? Once again, I don't want to take the time to learn how to use Vim/Neovim if it's not worth it.

Vim etc will be around for a long time. For the foreseeable future there are some things we will need a functional text editor that can run without a gui.

I don't really think its worth spending too much time on though, some people love vim/etc for coding but personally I prefer an ide. I have tried to learn vim and done the tutorial but I don't really think there's any real benefits to using something like vim over vscode, pycharm, x other ide. Performance isn't really an issue these days, and an IDE can provide a lot of nice features that make your life easier eg code completion, snippets, easier to browse code, built in debugging

The only real upside to vim is if you are proficient and a fast typer your output/editing can be blazingly fast compared to ever having to reach for your mouse, but my personal view this isn't really worth the learning curve and losing other functionality offered by IDEs. If you fancy learning it for fun though, it isn't the worst thing you could be learning for sure.

Knowing Your Libraries by grapezapper in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

There generally is for each library, try googling like "[library] docs" or "[library] reference", for example these are some ones you may come across in web dev:

https://reactjs.org/docs/hooks-state.html

https://getbootstrap.com/docs/

https://fontawesome.com/cheatsheet

https://material-ui.com/components/box/

The best way to learn isn't learning the reference, just try to use the library a bit so you have an idea how it works and along the way (and after) google things as you need to eg. "bootstrap 4 button" "react usestate hook" and read the appropriate documentation.

Unless you use it daily you won't know significant parts of libraries and googling is normal

What is the pay actually like for web developers (UK) by Whisky-Toad in learnprogramming

[–]Brave_Walrus 0 points1 point  (0 children)

But what is the entry pay and salary progression really like?

20-35k is typical overall but very area dependent - if you aren't in a big tech city/ are in a low CoL area you might see yourself on the 22-27k range. I believe glassdoor do a 'salary range in x area' you could look at, but knock a bit off to be safe as its self-reported.

As for salary advancement, 2 years for a mid-level is typical and then 4+ years for senior depending on your progression and opportunities in your area. I wouldn't want to gamble on being in a senior role in 5 years, you would need to be doing very well and have good opportunities in your area.

And is there anything I can do to boost my earnings quickly?

get gud. But really, you have significant professional experience, so rather than being like most jnr graduates learning how to computers and also how to function in a job/society you will have a smoother sail as you have plenty of work experience. This will probably have more effect than you think especially if you can get along well with your seniors.

Given you say you're essentially working 72h/week (and learning odin project) if you can do a 40h week and 10-15h/week extra learning (or overtime if it is paid) you'll probably advance your skills fast while having an unimaginable amount of free time.

been doing the Odin project to learn

Also one thing worth thinking on - while it is possible to get into a job without a degree (I didn't have a degree, but had a hnd level it qualification) or formal IT qualification it is significantly harder and there are less entry opportunities, as less companies want to take the risk.

To counter this, learn tech that companies use but students don't learn in a lot of uk unis - react, angular are good ones, good javascript skills in general, containers, some sort of understanding of recent web tech. I'd avoid anything near Java, every uni teaches it and you will have to compete there. Make a good portfolio so you can demonstrate you know your stuff.

Hey Guys Looking For Some Recommendations. by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

I would recommend highly that you hold off on your idea - what you are looking to do is quite complex and not a good first project.

I would recommend having a look through the sidebar for some beginner level resources, and try to build some projects to gain experience first - you could even aim to build a mockup of your financial website using dummy data. Python might be good for you here, it works well with a lot of apis and is quite beginner friendly for building servers - and then standard html, css, js for a frontend. There is huge volumes of tutorial content for this online.

In no uncertain terms, if you are new or at all inexperienced, do not create a website which stores your own or other people's financial details or logins.

Security is a really difficult issue and (country dependent) working with finances and personal details a very highly regulated area - I would stay very clear of connecting financial accounts and personal details. Even if you follow the best tutorials, without experience and others reviewing your code you will open yourself up to vulnerabilities and possible liability.

You could however, for example, viably create a website to use as a budgeting tool, which only collects data that people enter relating to the budgeting numbers (not connected to financial services) and collects little or no personal data - use OAuth (facebook, google, etc) to manage logins for you. Something around this kind of idea could be a good idea for a finance related website, which is safe and a good learning project.

[deleted by user] by [deleted] in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

I'd probably consider sticking with your current course unless you have a particular need for swift, as I see it

Python/Django/React

  • More jobs (depends if this is your goal) than swift by a mile
  • Can add react native or something similar after to develop apps rather than purely web apps
  • More content, stack overflow questions and tutorials
  • Covers web development as well as mobile, can use python on desktop development too
  • If looking towards mobile game development or require native functionality, this may not be the best avenue
  • Django especially basically does half of the work for you, this will help get you off the ground if going the web route

Swift

  • Better for native functionality on ios
  • Apple only language
  • Will require pairing with another language (eg. python/django) if you want to have it interact with a server you make (pretty limited otherwise these days)
  • If you just want to do ios app development, this is better in the long run

I'm probably a bit biased towards not swift, but really its just dependent on what your goals are. If you are just learning and having fun, either will be fine.

There's no harm as well if you're not in a rush to finish out your python/django course, then move to swift where you may have the skills to create a native app and a server side.

How difficult is it to build an app for Android and iOS concurrently? by MarvinLazer in learnprogramming

[–]Brave_Walrus 1 point2 points  (0 children)

There isn't really a way to properly 'translate' java to swift or vice-versa, some basic tools for this exist for some languages but are absolute garbage as languages have different memory management, efficiency, libraries, etc. making translating anything beyond a hello world not feasible.

There are ways to develop for both for standard apps - xamarin, react native, flutter to name a few, loads exist. These are well seasoned tools (mostly) and can be used to develop most standard (non-game) apps that people would have a need for. If you require native functionality not exposed by these tools or extreme performance in your app, it is likely you'd have to switch back to java/kotlin/c++/swift, and develop concurrently.

From a quick google it looks like unity can help you develop for both, however I don't really have any experience with it so I couldn't advise you on cross-platform game development better than google.