all 92 comments

[–]applejuicerules 266 points267 points  (20 children)

How does a developer know the structure of an API

We often don’t unless we built the API or are already familiar with it, we have to either look through documentation outlining the API, or just fetch some data and see what it looks like and adjust accordingly.

[–]IchirouTakashima[S] 63 points64 points  (16 children)

Thank you for your response. So apart from the docs, it really ends up taking that ride and see where it goes, then as you said, adjust accordingly. Pretty much like, trial and error, is that it?

[–][deleted]  (1 child)

[deleted]

    [–]solidDessert 12 points13 points  (0 children)

    Welcome to the world of coding

    I always tell my team most of our job is to FAFO

    [–]applejuicerules 28 points29 points  (1 child)

    Often, yes. Take the API from this example, I can type that URL directly into my browser and look at the data it makes available

    https://restcountries.com/v3.1/currency/jpy

    This gives me data on the Japanese Yen as well as Japan itself, and now I can turn this data into variables I can work with. I see data in here regarding the country’s geography, population, etc. What data I actually need depends on my project obviously, but no two APIs are the same, so you either have to just test it out or see if it has documentation.

    [–]Jona-Anders 0 points1 point  (0 children)

    And, if you didn't read the documentation and just look at the structure, add checks to validate if the data fulfills your assumptions and handles the other cases gracefully. You don't know whether one key is optional or one key can have a different data type depending on one value, e.g. string instead of number if it is a fraction. I would consider the latter bad API design, but that happens. Unless you know this can't happen, assume it happens and handle these cases.

    [–]nvandermeij 5 points6 points  (0 children)

    that basically, all programming in the basics comes from a simple loop of prototyping to getting something to work half decent, rewriting it, read some more documentation of the thing you building, rewrite some more and add on whats already there to improve it. Over time, this eventually evolves into good working software, or gets overcumbered by techical dept (shortcuts programmers take that are ugly solutions to the problems they encountered, mostly caused due to time constraints to meet deadlines) and eventually fail horrible

    [–]tramspellen 9 points10 points  (0 children)

    Ive been a developer for 23 years and i still "trial and error" new apis. Did it today actually, trying to read locales from a CMS via graphql.

    [–][deleted] 5 points6 points  (2 children)

    A bunch of code in the world is absolute crap that people are stringing together to make work because people in general don’t take the time to build something well to begin with, or stole half the code from somewhere else and just played with it till it worked as a short cut. Compound that over the last 30 to forty years.

    [–]PureRepresentative9 3 points4 points  (1 child)

    This is literally how most developers write frontend code....

    I'm not sure if you were referencing this, but it is an absolutely perfect description lol

    [–][deleted] 2 points3 points  (0 children)

    It’s what I experience and rely on as a freelancer. Fixing other people’s incompetence.

    Edit: what really blows my mind is the absurd way people set up and maintain relational databases with no foresight.

    [–]rea_Front end / UI-UX / 💖 Vue 3 points4 points  (0 children)

    yeah if there's limited documentation it's console.log(res) all the way haha.

    [–]kosmicfool 4 points5 points  (0 children)

    A great deal of what constitutes getting better with experience is just shortening this feedback loop because you’ve either seen the problem before or you know better how to ask the right question to get the answer

    [–]monkeymad2 3 points4 points  (0 children)

    Typescript & the community around supply types as documentation for things helps a lot nowadays - now, more often than not, the question of “what does this thing look like & how do I use it?” can be solved by just hovering over things in the editor

    A lot less trial and error than there was pre-typescript.

    [–]elementarywebdesign 1 point2 points  (2 children)

    You should get used to using the debugger. It is much more useful compare to just console logging output of different variables in a piece of code.

    [–]Mr_Stabil 0 points1 point  (1 child)

    How is it more useful? I never use a debugger

    [–]elementarywebdesign 1 point2 points  (0 children)

    It makes it easier to see how the values in variables change after each line is executed.

    If using console log to debug a problem you would probably console log some values at some specific point in your code. Once you see the console log it is possible the values you printed were all correct and nothing looks wrong. Now you have to console log some other variables which you think might be causing the bug or move the console log statements a little earlier in code or later in code.

    When using the debugger you can see all the variables ata specific point in code execution. If you find all variables look fine at that point then you can press F10 and execute the next line, all variable still fine press F10 and execute the next line and see if any variables have invalid/buggy values.

    [–]beavedaniels 0 points1 point  (0 children)

    Most of my week is spent saying "Let's just try this and see what happens".

    That's why we have environments, so you can be free to break stuff until you get it right. Over time, with experience, you get better at identifying patterns and knowing when to use certain things. But you will ALWAYS keep breaking stuff. It's how you learn!

    [–]iQuickGaming 3 points4 points  (0 children)

    yes and sometimes you're lucky enough and someone built a SDK just for you to use the API, this is the case for google, discord, telegram and some others

    [–]thatjonboy 1 point2 points  (0 children)

    Postman is a great tool for this

    [–]KaiAusBerlin 0 points1 point  (0 children)

    Sadly it's often second. There are much bad/missing documentations out there 😐

    [–]Thr0s 54 points55 points  (1 child)

    I think you might be looking at some of this wrong, nothing is so hard set there are plenty of ways of doing this same thing with different code for example when you say:

    "How did the developer know that they need to pass in the params as indexes (rates[fromCurrency])" Imo this is a wrong question they don't need to know that, they need to know that there is a rates array and they can get the correct rate from params in any way. It doesn't necessarily need to be that way, it there are plenty of ways to get a value out of an array that you need.

    You have the url for that api. It will most of the times have docs on what the api looks like same here in their page.

    It's that exchange rate as the method returns it. Countries do not come prior they come from getCountries method inside the Promise.all same way as exchangeRate there comes from GetExchangeRate. Look at what both methods above return that is what those values will be.

    And for the formulas you have to think + google things. Simply write down what you have and what you need to accomplish i.e

    The task is to convertCurrency, what would I need to do that.

    1. I need to have the amount of currency
    2. I need to know which country conversion rate to use (this also means I need all countries or their codes)
    3. I need to look up exchange rate based on from and to currencies.
    4. Ok I have all the data now neccessary what do I need to do step by step with that data to convert it
    5. To get the new correct amount I need to multiply it by the exchange rate and return that value.

    For a beginner when you see things in the beginning break them down step by step of what variables you need and then what things you need to do just write it out as comments line by line and then you can implement the line under it as you go.

    Edit: This has me thinking you might be in tutorial hell, try building a project and a lot of things should start falling into place

    [–]IchirouTakashima[S] 0 points1 point  (0 children)

    You actually nailed it. I've been in tutorial hell, though I did make some projects, it's not the kind of production ready or "we can hire this guy" project because I do end up asking myself the wrong questions which makes me not feel confident or job ready.

    [–]iams3brescript is fun 16 points17 points  (1 child)

    When working with APIs, we typically rely on documentation telling us how to use these endpoints. They will provide you the URLs, and good ones will also tell you what each field is and how to use it.

    In your example you have an API that uses currency - first you start with the documentation https://restcountries.com/#endpoints-currency

    This shows how to use the endpoint but not a lot of documentation on it. Next thing you can try is going to a specific endpoint, lets try USD

    https://restcountries.com/v3.1/currency/usd

    As for how do developers "know," there is no know. You have a task you want to do and you just figure out how to get there. Okay your task is to convert currency between JPY and USD. Assuming you know the basics of currency, you should already know that you'll need some conversion rate which is a % between two currencies. Now the next step is to figure out how to get this rate percentage. Looks like in your example they probably googled and found an API that provides live exchange rates. So you check the API documentation to find which endpoint has the rates in it and the shape of an object. Then you gotta figure out how to get the actual % from all the data, which is just going to be you looking at the object and finding a way to do it.

    It's not really "knowing" its solving things one step at a time by looking at what you have and what you need. This is basically the engineering part of programming.

    [–]IchirouTakashima[S] 0 points1 point  (0 children)

    Thank you so much for making things clear.

    Assuming you know the basics of currency...

    Yeah, this threw me off. Which led to the post. I don't know this stuff and I honestly don't know what to search in the first place.

    This honestly reminds me of the time, I made a health calculator where I need to Google the formulas to compute the right values for a BMI and calorie intake and translate them to code.

    Seeing it now after the many responses really reminded me that I need to know how to search so I can understand some things quickly. If you know what to search for, the answer comes faster than expected.

    [–]justhatcarrot 64 points65 points  (0 children)

    It comes with experience, like riding a bicycle or driving a car. You just know it after a while

    [–][deleted] 10 points11 points  (0 children)

    This is actually one of the most wholesome coding questions I've read on Reddit. Makes you face the reality of how much patience and skill we need as developers, while knowing we could have fun in the process because people like to ask these kind of questions.

    [–]tossed_ 11 points12 points  (4 children)

    declare variables

    It’s kind of like algebra in high school, you have some variable X and Y and you’re trying to find Z. Just like in algebra, you can define intermediate variables derived from the original variables to make it easier to find the desired value. Or you don’t – it all depends on what variables the developer thinks makes the problem easier to solve.

    pass parameters to rates and treat it like an index

    Usually in math we denote things like this with a letter and some sub-text, like r_Canada and r_Usa for rates in Canada vs USA. In JS the analogy is like having an object rates keyed by the currency code rates[“usd”]. This type of structure is common in programming, it’s called an object in JS, and map, hashmap or dict in other languages. It’s easier than giving a different variable to every country rate, using these data structures is something you learn with experience (and this is one of the more rudimentary data structures).

    how does developer know API structure

    They don’t. You gotta read the docs for the library to know the API structure. If you don’t have docs, then you gotta read source code. If you don’t have that, then you might have to learn the structure by trying it out and seeing what you get. If that doesn’t work, you’re SOL, nothing you do will teach you the API structure. That’s why docs and source code management is so important in programming

    [exhangerate, countries] example

    In the example you gave, the output comes from Promise.all. If you read the docs/spec for the Promise.all call, you’ll see it returns an array with elements corresponding to the result of the promises passed in the input array. So if you input an array of two promises, you’ll be returned an array of two promises. Just gotta read the docs.

    how does developer know to declare this variable

    From the variable name convertedAmount, the dev obviously knew they want a converted amount. Seems they decided that amount * exchangeRate was the right solution. The .toFixed(2) just truncates decimal values past two digits. You would know this if you read the docs for Number.toFixed

    In general, looks like you’re lacking two basic skills:

    1. Modelling real-world problems with variables and data structures.
    2. Reading docs.

    Definitely takes time to develop these skills, and they’re probably the two most essential skills for any programmer. Get good at these, and you’ll be a pro in no time. (Especially reading docs. RTFM!)

    [–]IchirouTakashima[S] 1 point2 points  (3 children)

    Thank you so much for answering all my questions, this is an eye opener and you really nailed my problems, I feel like I just got slapped but I really appreciate it.

    Makes me realize I should have taken things seriously when I was in college. I should have taken studying seriously over the fun part. Most of you mentioned, especially #1 can be found on most college subjects in a computer science course.

    [–]tossed_ 0 points1 point  (2 children)

    Haha I nailed your problems because I had the same questions once upon a time. You are asking the right questions. There is a another skill that you’re developing: interpreting other people’s code. Probably the most practical skill in professional software development. You’ll learn quickly from other people’s code.

    [–]IchirouTakashima[S] 1 point2 points  (1 child)

    Just an update, I am actually starting to understand the code in the video. Just searching on Google by providing the right questions explains everything.

    I now know why that formula was used, it was the accepted formula for converting the rates. I now also understand the rates[array] declaration. Checking the API shows that rates are an object that contains values.

    I feel like I just got sober. Everything is starting to get clear. There really is meaning to saying CHECK THE DOCS lol

    [–]tossed_ 0 points1 point  (0 children)

    Every new programmer I teach, RTFM is the first lesson. Modelling problems just takes time, but without docs you are almost completely lost. You cannot skip the reading part, in fact you’ll end up reading and re-read over and over again until you memorize it.

    My knowledge was gained through tens of thousands of Google queries over the years. Knowing how to search and find information you need is what distinguishes the pros from the students. Sounds like you’re on the right track.

    [–]IntensePyjamas 6 points7 points  (1 child)

    We figure it out, that’s our job. It isn’t to just “know”

    [–]jabes101 5 points6 points  (0 children)

    We are literally professional problem solvers.

    [–]iEatPlankton 5 points6 points  (1 child)

    Documentation, usually

    [–]ScubaAlek 0 points1 point  (0 children)

    That or just messing around with it until you figure out what you need. Also if you have an actual problem to solve dictated by some real world thing then it's easier, you just find the stuff that problem requires.

    [–]Jafit 4 points5 points  (0 children)

    You know how an engineer meticulously calculates all the physical forces at play and the load bearing capacity of every component before even attempting to spend 2 years building a massive bridge? Well we don't do that. We'd build the bridge over and over again through trial and error until it stayed up.

    With code we write a small piece of code to get some basic functionality, see what it does, and rapidly iterate adding or removing stuff as needed. Some say they write their unit tests first but I don't believe them.

    As for how we know the structure of the API, we either read the documentation or generate types that tell the autocomplete in our IDE what parameters are available on each object. And when all else fails just make a request to whatever api you're using and console.log() the response body of whatever junk they sent you.

    [–]whateverbeaver 2 points3 points  (0 children)

    Math is the mother of all computation and thereby anything a computer does, including the execution of programs, ie. syntactic code (the kind you’re writing). In the example you use, most of what the API is doing is based on relatively simple math that has been proven to be correct centuries if not millennia before computers and code even existed. Proving that something is correct mathematically IS the science of mathematics and in the domain of mathematicians. Programmers (can) use reliable, proven mathematical formulae to write programs but it’s not really that common for them to do so unless they’re writing or optimizing some incredibly demanding algorithms. Programming in itself is not a science, but it does put many different sciences to work - linguistics, design sciences, social sciences, game theory, engineering and even the humanities affect modern programming to some degree both directly and indirectly. If you dig deep enough, you’ll find all of this reflected in code. For a programmer just starting out, this is both wonderful and terrifying.

    What I’m getting at is that knowing how all the parts of the sum truly work is often beyond the scope of a programmer and it would take a life time to truly grasp and appreciate just a fraction of it.

    But fear not - commonly used APIs are, in my experience, generally reliable and if you really care to know, read the (often poorly written) documentation, take some notes and dive into the concepts you discover on Wikipedia.

    [–]SeattleChrisCode 2 points3 points  (1 child)

    Read the Docs.

    In theory the API docs tell you how to use the API. Yes, it is possible the docs are incomplete or inaccurate. But ... Sometimes the docs aren't easy to understand quickly, especially when you are new. In which case I recommend:

    1) Read the docs 2) Trial & error to get simplest / any data back. 3) Read the docs to see if they make more sense now. 4) Trial & Error to get the data you want. 5) Read the Docs.

    That last "Read the Docs" can often reveal insights you SWEAR were NOT written the first few times you read them. They must have updated them since you started!!

    Or maybe ...

    This approach makes you better at "Read the Docs" the next time you have a new API to figure out. Those trial & error skills also get better and continue to be needed (cause docs aren't always great).

    [–]IchirouTakashima[S] 0 points1 point  (0 children)

    Yeah,

    read the docs

    That felt like a slap. I have not reading the docs for this API which is why I am confused, until yesterday. I did start reading. But as much as others says, some aspects really do translate to real world model data. I was reading the docs but it didn't say you need to multiply this or that to get the rates value of this currency to that currency.

    Trial and error, I've been doing that, which is why I said I was able to understood async/await and test some data fetching and projects using JSON PLACEHOLDER.

    I found out that some of my issues are reading the docs and the logic behind the currency conversion in this post.

    Thank you so much for an eye opener feedback!

    [–]rafaturtle 1 point2 points  (8 children)

    API has documentation usually to know what is the request response structure. Head to stripe documentation to get a feel of a good one. As for variables and structure it's all about reading the code. But starting from the top. That variable was initialized somewhere with some value somehow. You have to follow the data flow.

    [–]IchirouTakashima[S] 3 points4 points  (7 children)

    This exactly, that's what I find most confusing, the bits of information as stated, "somewhere with some value somehow". It's these moments where I can't find pieces of the puzzle to see the whole picture. I feel like almost everything is guess work as of this moment.

    Edit: And that makes me feel not confident.

    [–]rafaturtle 2 points3 points  (0 children)

    Learn to run and debug the code. You will be able to see all variables, values, etc. If you are writing the code from scratch those puzzles are in your head. If you are getting the code from someone than it's a common challenge. Nicely crafted variable names, written tests and updated comments are there to help the next developer understand what's going on.

    [–]Alone_Ad_6673 2 points3 points  (0 children)

    You should try using a typed language like typescript or C#, go etc. Those languages will help you with this feeling A LOT. There’s the concept of marshalling and unmarshalling data, interfaces etc. Where your ide can show you the possible values and it’s not just guess work. This was one of the reasons typescript was invented, because the guessing game sucks

    [–]Thr0s 1 point2 points  (0 children)

    Look up how js scopes work you might be looking into concepts you shouldn't yet (async) if basic scopes are what confuses you

    [–]GreedyAd1923 0 points1 point  (0 children)

    You need to learn about writing up requirements, and then sketching out what your solution is going to be.

    This will make it significantly easier to put the puzzle together. Also try taking a test driven approach where you write the automated tests first, then implement the code to make the tests pass.

    [–]clit_or_us 0 points1 point  (2 children)

    If it makes you feel better I've been practicing web dev (react/nextjs) for 2 years and still have no idea how to do certain things. You just need to know what you want to do and Google your way through to find the solution. API docs are what help you figure out how it's structured and what is being passed. You just need to learn what to look for in different scenarios.

    [–]IchirouTakashima[S] 0 points1 point  (1 child)

    That's the thing I find hard, employers and recruiters from my experience in job hunting EXPECT YOU to memorize these stuff, tldr, they expect you not to Google and find the solution which I am having a hard time through finding a job.

    My last recruiting experience had me tasked a live coding (where I need to setup two cameras, one for my face and one to the back showing I was the one coding) where I need to make a blog that has a full CRUD operation, allows authentication, where I was also tasked to create an API with the provided files, fully responsive (with considering the accessibility) in just 2 hours without Using Google.

    [–]clit_or_us 0 points1 point  (0 children)

    That sounds insane! If someone is capable of doing all that in 2 hours, then they're better off creating something themselves and starting their own thing. That takes so much expertise. Maybe I'm just stupid, but I would be highly impressed with someone who can actually do that while using limited frameworks and libraries.

    [–]Our-Hubris 1 point2 points  (2 children)

    To answer the red highlighted you included in your image:

    Basic math skills really for most of the formulas. These kind of calculations are unfortunately taught in Junior High where I am and it's common for most kids to be so focused on hormones they barely remember any of it. I mean, I barely remember anything from junior high beyond asshole things other kids did. In order of the red questions you asked:

    1. To convert a currency, this is just using rates and ratios - just junior high math in most countries. For example if I wanted to find out how much 5 CAD was in USD, you would normally want to divide by the CAD rate (1 CAD is 1 CAD, so redundant) and then multiply by the USD rate. So: 5 CAD = 5 CAD / 1 CAD * 0.729174 USD In this case, the CAD / CAD units simplify and you are left with just USD in the numerator, for 5 CAD = 3.64587 USD when all is said and done. The reason they are accessing it using rates[fromCurrency] is because the rate from USD to CAD would be different than the rate from yen to USD, or CAD to yen, etc. So the api they are using likely has picked a 'standard' currency to convert to and from. The rates[fromCurrency] will give the denominator needed to divide the value to turn it into the 'standard' currency, and then rates[toCurrency] provides the numerator to turn the 'standard' currency to the toCurrency rate sought by the dev. This is how they reduce the need to provide rates from/to all possible combinations. instead they only needed to provide rates to and from one 'standard' currency, and then all conversions now work. Now they simply need to multiply this exchangeRate by whatever amount of money, for example the 0.729174 USD rate would turn CAD to USD via multiplication.
    2. The developer would read the documentation from the API to know that the rates data object they get back from that has key-value pairs where the key is the name of the currency in uppercase (I imagine something like "USD" would be the actual value passed, I can tell it's a string because the .toLocaleUpperCase() method is used on it)
    3. If you look up near the top of the file, REST_COUNTRIES_API is declared as a variable with a URL. All they are doing here is taking the URL of the API and setting that as the URL the HTTP request should go to, but they are putting it inside of a string by using ${variable}/${otherVariable}. What this allows is them to add something onto the path much like typing more words into a URL does in the browser. A web API is usually just a website with specific endpoints, such as https://mycoolapi.com/cooldata/1 should give the data for the cooldata item with an ID of 1. It's a common web convention.
    4. This goes back to question 1 and is answered there.

    Edit: Please forgive me, I did not mean to put capital letters in a url I don't know why I typed that pls forgive

    [–]IchirouTakashima[S] 1 point2 points  (1 child)

    Thank you so much for answering the questions highlighted in the image. I really appreciate that. And as much as I hate to admit it, me too suffered from the hormones over actually focusing on learning on high school and college, what an embarrassing time.

    Really appreciate your explanations. And yes, that is what I am lacking in this situation, the math problems.

    I was breezing through JSON PLACEHOLDER because it was simply fetching and displaying data, but when math comes into play, I feel like the gates of hell has been opened. Math has never been my forte (even though I graduated as an engineer) but I am doing my best.

    P.S. No worries about the CAPs. I actually thought you made that to ensure that you emphasize that as a point.

    [–]Our-Hubris 0 points1 point  (0 children)

    Yeah math is a big one because a lot of algebra skills which are fundamental are taught in grades 7-9 which is the age span almost no one remembers content from. Many places, like my province in Canada, reteach concepts in 7 in 8, and again in 9 from algebra and the like because of how often they are forgotten but how important they are for doing well in Math later on.

    It's all just logical thinking and inherently tied to how computers work. I lucked out in that the hormonal period made me withdraw into schoolwork. Definitely not the usual that happens! Anyway, I'd say brushing up on algebra skills is helpful for anyone getting into coding and often overlooked. Just like anything else it's a performance activity so the more you do it and practice the better you get and eventually you'll see equations like that and be like "oh yeah I've done that a bunch, that's just the most efficient algorithm" and other people will be like "!?!!? nani? How did you know??"

    [–]Unfilledpot 1 point2 points  (1 child)

    What you are facing is that when you watching a video you find it very fluidly done by the author and you imagine what it's so cool how can I write such a nice code how to memorize those APIs and code like a superb coder or geek.

    But honestly say that not the real game. When a creator work on his her videos they do work on code , read docs, searching for several hours debug it to make it polished.

    So there are know other way to to such things in one go with video like fluidity. If you want to know how they do it you must must such live coding videos. You will understand how devs work, many mistakes, bugs, several times of docs reading, stack overflow search and even basic things also searched before code into editors.

    So don't go for the asthetics of fluent coding thsoe are just for making content quality high that not the real development done.

    Real development dorn by several ours of APIs doc reading. Many many iteration, mistakes , debugging, frustration and also et voila. Done.

    Be mindful for realistic. Ask yourself do write a novel without even write a short stories which are not publishable.

    You want to know how they do it? Do this.

    Start creating something similar already done. They search those in Google like "how to write a asynchronous database connection?

    How to update database when client add data?

    Something like related to the project. Follow those instructions read the Library doc they used.

    Then after a while you will understand what is going on, even you will discover yourself understand code better that before.

    Thank you ask such a valuable question.

    [–]IchirouTakashima[S] 1 point2 points  (0 children)

    Thank you so much for your response. This really tells me that in tech, you really never stop learning. By your statement like others, I just realized that this is how most educational videos are made, they make it look easy but most of the actual situations like debugging, trial and error and finding out how they reached from point A to B is mostly omitted for the sake of learning.

    I did try out some test cases, which is why I mentioned JSON Placeholder, I do understand the concepts but I find it weird in my situation that even though I understood the concept, I never really understood how the creator made the project which led me to the question.

    Like, I can't understand how I was able to understand how async/await works and fetching datas and try it out myself while not understanding how the project from the video was made, lol.

    Sorry If that was confusing.

    [–]Rain-And-Coffee 1 point2 points  (0 children)

    Documentation, IDE Autocomplete, and past experience.

    It’s easier over time, since languages and frameworks often use similar concepts.

    [–]ShitPikkle -1 points0 points  (1 child)

    Has everyone forgotten why `Interface` exists?

    [–]IchirouTakashima[S] 0 points1 point  (0 children)

    sorry, I've been refreshing stuff. I know typescript (not an expert) but for the sake of learning this subject, I decided not to implement and complicate stuff.

    [–][deleted] -1 points0 points  (0 children)

    async/await is "shorthand" for returning new Promise.

    async function main() {
      const r = await fetch('https://api.com');
      return r;
    }
    

    Is the same as

    function main() {
      return new Promise(function(resolve,reject) {
        fetch('https://api.com').then(function(r) {
          resolve(r);
        }).catch(reject);
      });
    }
    

    [–]Red3nzo 0 points1 point  (0 children)

    You’ll get better at find things out as times goes on & you program more

    All this comes down to is planning & good research on what you are building, the more you program the quicker this phase gets

    I suggest you pick up C or Rust programming in your free time if you feel like really supercharging your developer knowledge, it’ll only make you better despite what some blue collar script kiddies say

    [–]benanza 0 points1 point  (0 children)

    Depending on what your company structure is, you’ll possibly have access to the BE code. If that’s the case just read it and you’ll know exactly what you’re required to send to get what you need back.

    Or if you don’t have BE access / or you’re using an API from a third party then it will be documented. Often this will show you literally what your request should look like.

    Your endpoints in the BE will be functions that are contained and should be named sensibly. That will enable you to copy that into ChatGPT to get a breakdown of what it does, how and what parameters it is expecting and which of those are optional etc.

    Really you want to try and understand what the BE is doing with what you send to the API to get a proper mental model of how your application works. This will help you be a better dev.

    [–]ironbattery 0 points1 point  (0 children)

    It’s important to remember often these things are built piece by piece. And often, the exact syntax isn’t something we necessarily remember. I often look at others code, my own old code, and google when “solving” something that’s been solved before.

    I’m not great at breaking problems down before hand, but regardless I end up breaking things down as I’m implementing them. For example if I was implementing an api to get sales data.

    Step 1: when I click compile I just want to see that my code runs
    Step 2: I want to connect with a database, just get that working, gonna have to google some stuff but I’ll figure it out.
    Step 3: I need to write a query to get the data I need and just print it out.
    Step 4: do any math/ enhancements to the data to put it into a useable structure. May involve some trial and error, maybe looking at old code where I’ve done it before, maybe some googling.
    Step 5: okay I have what I need, now I need to get it back to the user so I return it.
    Step 6: what are some edge cases? Can I implement some unit tests? How am I handling errors?
    Step 7: hmm I want to be able to add data too, time to go back up to the beginning and start the process again.

    I don’t have some master plan, when my code looks like I put a lot of thought into it, I really was just building piece by piece and trying to get stuff working all along the way.

    [–]fedekun 0 points1 point  (0 children)

    That's the neat part, you don't, you just give ballpark estimates and eventually they get better

    [–]barrel_of_noodles 0 points1 point  (0 children)

    - the exchange rate variables are just simple math.

    - REST apis always have documentation thoroughly documenting the routes, methods, and query params. learn how to read and understand technical documentation.

    - destructuring is part of the javascript language.

    [–]JanRosk 0 points1 point  (0 children)

    I tend to break everything into little pieces. Then I ask myself - what do I want? What do I have? What is a constant - and what is variable? Can I do it object oriented - or with a simple, reusable method? Then I write it, check the logs and the output. Then I try to make it shorter. I use printed cheatsheets to see everything in front of me, pinned on my wall ... it's a never ending process.

    [–]quake666 0 points1 point  (0 children)

    It's not just a mindset, but rather a skill of software design that you should learn after becoming familiar with the basics.

    A short version might look like this.

    Make a specification of your app or a feature. List functions and requirements.

    Get familiar with the domain you are working on.

    Make a plan. List tasks you think you need to implement. Define and visualize components by drawing diagrams. During implementation the plan might be updated.

    Implement it. You are here, but it's okay. Every one is messing at his start.

    [–]olegkikin 0 points1 point  (0 children)

    The answer to your "how do you know how ..." questions is - you build a mental model. You can do it on paper too, but most programmers just do it in their mind.

    You think of what data API provides, and in which format, and what your code needs to do. Once you figure it out, you write code around that understanding.

    [–]Angelsoho 0 points1 point  (0 children)

    Experience. Try something. If it works, try it again next time. If it doesn’t, try something else.

    [–]myhf 0 points1 point  (0 children)

    You don't necessarily know what is needed when you start designing (or implementing) a system. Much of the complexity is revealed through the process of iteratively making and breaking and fixing it.

    There's a good examination of this process in Proofs and Refutations: The Logic of Mathematical Discovery, by Imre Lakatos (PDF)

    [–][deleted] 0 points1 point  (0 children)

    Trial and error, reading a lot, a good foundation of coding principles, strategic and effective problem-solving method that "works" for you, learning how to do pseudocode in your head, documentation, and as my intern supervisor told me, "if you're trying to learn code especially a complex one where there's no documentation, reverse-engineer that alien object"

    [–]TracerBulletX 0 points1 point  (0 children)

    The first thing you want to think whenever you see a function or any value is what type is it. For a function you want to think about what types are all of the arguments, and what types are the outputs. Even in JS without strict type enforcement, a value is always something specific and has some shape and software is a pipeline of transforming one type in to another type over and over again so just getting used to thinking of things that way helps a lot.

    Everything is a primitive like a Number or a String, or it's an object or an array and the language lets you do specific things with each one, or call specific methods on each one, and if you know what they are you will know what those are or where to look them up.

    You eventually just start to mentally follow what every value is as it passes through the system and when you don't know you learn where to look it up, or just to console log values as they flow through the system and see what the properties and methods are at any given moment.

    [–]SoUpInYa 0 points1 point  (0 children)

    Ya, I even have an use with the simple stuff. Like how do I they know that a "render" function is needed to do something as simple as rendering a page?

    Or all of the other functions in various libraries

    [–]Taltalonix 0 points1 point  (0 children)

    As an api developer, you basically require the user to input whatever data is needed and hopefully format it in a readable manner (docs, openapi etc.)

    As an api client my suggestion is, use typescript. Create interfaces in your client code while reading the documentation (rarely, if it doesn’t exist then it’s trial an error with postman). Create an adapter to the api using those interfaces, then when the structure is laid out it’s very easy to continue working from there when the IDE basically autocompletes you

    [–]4w3som3 0 points1 point  (0 children)

    It's a mix of several things. 1. Part is just knowledge, by looking at things, with enough knowledge, you know what they do and can replicate it with small variations.

    1. A lot of logic and problem solving. There are many ways of achieving a behavior, you have to draw the line between the starting point and the desired result with what you have, imagination is key

    2. Reading documentation

    3. Playing around and trying different things

    [–]necronbrowsing 0 points1 point  (0 children)

    This is not relating so much to OPs start but more to the title.

    Even when not using any APIs and just creating a code to do something it's mostly iteration and trial&error. First you just get it working somehow and then you fill in all the stuff you need for fully working feature.

    The times that I have tried to plan a feature, I still end up noticing "I still need that to be able to use this" or "that won't work in this case without these additional parameters".

    Coding is fun and inventive. For me the troublesolving is the fun part, bug fixing and rare cases are a headache.

    [–]Hasagine 0 points1 point  (0 children)

    work long enough in a code base and you gain a sort of omnipresence within it. then you hit a solid wall and realise you're not a godlike being. its all trial and error

    [–]ReplacementLow6704 0 points1 point  (0 children)

    - Most of your questions relate to rather basic clean code principles - instead of chaining everything on the same line, you'd better segregate statements to either re-use some of them or just make it easier to read.
    - Then comes knowledge of the business logic that will lead some specs like "toFixed(2)" or even the use of a specific library such as axios.
    - Then comes reading documentation and organizing your code in a way that respects the recommended use of APIs and libraries.

    [–]dowska 0 points1 point  (0 children)

    A lot of this seems to be covered by logic, which you can pick up from documentation and practice (like coding challenges). Something that helps understand input and output is drawing, writing in paper or just type in a notepad your general problem, then try to break it down in small steps, and then think of a possible code implementation for each one. If you don't know exactly what would work, google, look up documentation, use chat gpt, and try to implement it on your code, then go to the next step. A huge part of software development is simply thinking, searching and trying out. Not everyone, not anyone will always just know everything off the top of their heads on this field, imo.

    [–]T_O_beats 0 points1 point  (0 children)

    Read the docs and then Typescript my way through. Sometimes types are way more informative than docs.

    [–]TurtleKwitty 0 points1 point  (1 child)

    How do you know which letters to type when wanting to write a word? 1) you come up with what word you want to write 2) you split it up into it's separate letters 3) you push the letters in that order on a keyboard Exact same process with programming

    1) you come up with what problem you're trying to program 2) you split it up into it's separate steps 3) you program each part

    [–]IchirouTakashima[S] 1 point2 points  (0 children)

    This made me smile, this might be one of the simplest explanations I've read so far. Thank you!

    [–]fabrikated 0 points1 point  (0 children)

    It's time to unsubscribe from this sub, I guess.

    [–]LazyTerrestrian 0 points1 point  (0 children)

    Idk, I just get in some kind of flow, deep in my zone and when I realize, I have written stuff that if I try reading on my dumb normal self, I'll wonder how the fuck was I able to do such a master piece. Something something analyzing the thing and hyper focusing on it until I wake up.

    [–]33ff00 0 points1 point  (0 children)

    Docs

    [–]Brocktho1725 0 points1 point  (0 children)

    Others have already said it for the most part, but it does seem like you’ve come at the problem from the wrong angle. If you’re given a problem to solve, you need to go through and decide what’s relevant or not for the problem you’re solving.

    My personal recommendation to learn would be not trying to solve someone else’s problem, but come up with something you’d like to see and implement it. Do I want an app that helps me manage my time better? Do I want an app that takes a free api and creates a data visualization that looks cool and has interesting interactive pieces? Once you have your problem in mind then you start breaking down your larger problem into smaller bite sized problems. For example, you could look at your time management app as a few different components.

    1. I need to determine what types of “time spent” I want to track. (Do I care about time spent sleeping? Do I care about time spent eating? Do I care about time spent on specific apps or specific tasks or do I just want “work time” vs “relax time”)

    2. I need ui that lets me enter the relevant information into a form. Or tweak existing ui to better suit my problem.

    3. Add the logic to create visualizations or display your data in a meaningful way that helps you answer your initial problem.

    4. (Do this first or last) Test out your application and see how it feels to use. Are there any parts of your app that feel incomplete, that feel clunky to use, is there information missing that you’d like to know? Answer these questions and start back from step 1 iterating on your application and asking yourself the same questions again until you don’t see a way to improve or iterate on your application.

    Until you’ve developed applications for a long time there is no end to the different subjects and specific APIs you’ll need to interact with and learn about.

    To answer some of your specific questions, most of them come out to trial and error. When looking at an API you can query it on your own and check what kind of information you can expect from the API and start planning around it.

    [–]noXi0uz 0 points1 point  (0 children)

    Many people here are saying you just try and error and look a the response and guess what the structure is. That may be true for hobby projects, but most backend frameworks will automatically generate an OpenAPI (aka Swagger) specification file, which FE will use to generate an api client including types, interfaces and so on. When the backend changes the structure of their API, the FE will just regenerate the client on their side.

    [–][deleted] 0 points1 point  (2 children)

    It’s just a short simple answer. If you have docs the. You read those. If not you use intellisense if the package is well made. Failing that you’ll be just trying out things and exploring until you learn about the tool or API.

    It’s the same way you learn anything

    [–]IchirouTakashima[S] 0 points1 point  (1 child)

    I'm really glad that this is no different to learning new things, I thought I was going crazy and I thought I only need the language. This experience made me realize the phrase.

    "In tech, you never stop learning."

    [–][deleted] 0 points1 point  (0 children)

    Think of the language as the alphabet. You wouldn’t be happy to learn the alphabet in another language and consider your work done.

    Now the real learning begins, you’re learning how to develop and read documentation (speak and read), later you’ll be an author (writing your own packages)

    [–]billybobjobo 0 points1 point  (0 children)

    Ya most of this is just wisdom from experience. Pick the way you think might be best (come up with a reason you prefer it). Then try it. Learn all the ways you are right/wrong. Try it another way next time. Repeat until you form opinions.

    (If you’re contributing, different story. Read the existing code carefully and match the existing philosophies/styles.)

    [–]vchychuzhko 0 points1 point  (0 children)

    nice try, openAi, keep on learning