nus-cs2103-AY1819S1 / forum

A repo to hold the issue tracker for module discussions
1 stars 1 forks source link

Question regarding "hard-coding" vs using external APIs #79

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi Prof et al.,

I also have another query to ask about. I'll try to simplify and summarize my doubt(s) and/or question(s).

Firstly, it is okay to "hard-code" rather than use external API right? Using (approved) external APIs may involve investing time and effort, and the student must also make sure it integrates well with the project. Moreover, not every student is at the same level.

I feel that I am still somewhat a novice programmer and software engineer. My opinion is also that Java API is very rich with many libraries. Perhaps, frankly, I would not also call it "hard-coding". There are probably intuitive ways to "program" our feature.

{EDIT (as I forgot to mention earlier): For example, like using some Data Structures and/or Algorithms we have learnt before, or new ones we self-learn? Haha..}

On another note, yes, maybe it may (or may not )involve more "dirty work" (i.e. need to spend time coding and etc) if we do not use external APIs, but I think maybe the student can learn a lot through the process too? :)

I am also referring to instances where we have to teach ourselves how to communicate with things like HTML or json (Do pardon my limited knowledge. To my understanding and also if my memory serves well, json and html are quite related to each other?)

Please excuse me for this seemingly rather lengthy post but I hope the readers do sort of get the drift, haha.

ghost commented 5 years ago

Perhaps the above is too lengthy, I think I will summarize my query as follows:

It is perfectly okay and okay to not use external APIs for our enhancement(s) if the task seems too insurmountable and challenging, and yet, still possible to produce a rather decent enhancement too right? :)

azhikai commented 5 years ago

Personally I don't see a problem, but more of a why?

Do pardon my limited knowledge. To my understanding and also if my memory serves well, json and html are quite related to each other?

No, not really.

JSON is a format used to store and exchange data. It's not directly related to HTML, but it can be used for data retrieval which is then displayed via HTML. It is also commonly used for web services.

ghost commented 5 years ago

Yea @AZhiKai that's it!

I do remember trying before to communicate with an external API (if I remember it was Google Maps), and yeah, it involves dealing with HTML and that's where JSON also came into the picture. Long story short, I failed miserably xD (maybe I could have possibly learnt how to get my app to communicate with Google Maps if I spent more time and effort, but, really, to me, it was kind of hard especially with the limited knowledge I have)

JSON is a format for storing/receiving HTML data?

azhikai commented 5 years ago

JSON is a format for storing/receiving HTML data?

It's a format that stores data. I'm not quite sure on what you meant by "receiving HTML data". Perhaps let me give you an example:

Say you're building a very simple web app using Google Maps API and you asked your user to key in their current location, and the place they want to go, you can make a request to the API with the information which your user provided (current location and destination), and the API will return you the result in JSON format which you can then deserialize it and display as HTML results to your user. The following is an example taken from Google Maps Platform.

{
   "destination_addresses" : [ "San Francisco, CA, USA", "Victoria, BC, Canada" ],
   "origin_addresses" : [ "Vancouver, BC, Canada", "Seattle, WA, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "1,529 km",
                  "value" : 1528699
               },
               "duration" : {
                  "text" : "14 hours 56 mins",
                  "value" : 53778
               },
               "status" : "OK"
            },
            {
               "distance" : {
                  "text" : "115 km",
                  "value" : 114513
               },
               "duration" : {
                  "text" : "3 hours 14 mins",
                  "value" : 11614
               },
               "status" : "OK"
            }
         ]
      },
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "1,300 km",
                  "value" : 1299985
               },
               "duration" : {
                  "text" : "12 hours 25 mins",
                  "value" : 44695
               },
               "status" : "OK"
            },
            {
               "distance" : {
                  "text" : "297 km",
                  "value" : 296838
               },
               "duration" : {
                  "text" : "4 hours 48 mins",
                  "value" : 17285
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}
rongjiecomputer commented 5 years ago

You can see JSON as a general-purpose structured data format that is widely supported by many programming languages. JSON is closer to XML (also used for storing general data) than HTML (very specific for representing text semantic of a document, think <body>, <head>, <header>, <nav>, <aside> etc.).

rongjiecomputer commented 5 years ago

Google Maps Platform provides APIs for programmers to interact with Google Maps, so you don't have to pretend that you are a browser and manually hard-code the scraping code to scrape data from Google Maps webpage (Google might block you with reCaptcha due to high volume of requests).

Many Google Maps APIs are just sending HTTP request to a designated URL and Google will return you a JSON text with the data you need. https://developers.google.com/maps/documentation/geocoding/start has a tutorial about how to get the API key, how to structure the API URL, the returned JSON (though Geolocation API is probably not the API you are looking for).

Google Maps can also give you XML data if you are more comfortable with manipulating XML, see the documentation.

ghost commented 5 years ago

Thanks, guys! Yup, I did remember getting an API key in the past. Anyways, I am just asking, but however, at the present moment, I probably do not need to communicate with Google Maps server using Google Maps API :P

ghost commented 5 years ago

Anyway, what I also meant and in a way, asking about is that...

azhikai commented 5 years ago

I think it's really up to what your team is doing. If whatever you're doing requires an external services such as GMaps, then you'd have to use it, unless you don't mind dropping that feature entirely.

All in all, do what you and your team are comfortable with, while taking into consideration of the deadlines and deliverable.

damithc commented 5 years ago

It is perfectly okay and okay to not use external APIs for our enhancement(s) if the task seems too insurmountable and challenging, and yet, still possible to produce a rather decent enhancement too right? :)

Yes @HEARTOFAL1ON, it is fine not to use an external API or even write your own simpler version of an API. 👍