Jump to content




API's are a pain. But programs are easy. [PLEASE READ] [PLEASE SPREAD]


23 replies to this topic

#1 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

Posted 07 December 2012 - 05:42 PM

Hey guys,
I was looking for games and I saw the perfect game. TETRIS! But turns out you HAVE TO INSTALL API'S. Why not just make it a program anyway? Its as easy as putting shell.run("APIName") at the top of your code! And its technically less work because you dont have to write the API in functions. for example let's pretend a API with the name of BobTheBuilder (I know its a stupid name but were pretending) then every function would have to be BobTheBuilder.functionName() but by using a program its just functionName().
Please share this with a lot of people so we can stop needing to install API's!

#2 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 07 December 2012 - 05:45 PM

View Postwalia6, on 07 December 2012 - 05:42 PM, said:

Hey guys,
I was looking for games and I saw the perfect game. TETRIS! But turns out you HAVE TO INSTALL API'S. Why not just make it a program anyway? Its as easy as putting shell.run("APIName") at the top of your code! And its technically less work because lets a API with the name of BobTheBuilder then every function would have to be BobTheBuilder.functionName() but by using a program its just functionName()
Please share this with a lot of people so we can stop needing to install API's!

I like the "api.function()" thing. It keeps your code organized. However, I never use API's, I just put apiname = {} at the top of my code, then you can define apiname.functionname(). Just my 2ยข

#3 faubiguy

  • Members
  • 213 posts

Posted 07 December 2012 - 06:23 PM

The main purpose of APIs is shared use of code, in multiple programs (making them libraries). Separate files are needed for this unless the full contents of the api is going to be in every program that uses it. Putting APIs in separate tables, so you call BobTheBuilder.build() instead of just build() is useful for avoiding function collisions, in the case that two different APIs have different functions that have the same name.

Also, in case you're referring to my Tetris game, I made it automatically download the needed APIs now.

#4 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

Posted 07 December 2012 - 06:26 PM

XD i was referring to yours. I didnt know that because i saw it off of nitrogen fingers' post

mind linking me to the post?

#5 faubiguy

  • Members
  • 213 posts

Posted 07 December 2012 - 06:27 PM

You can link to it if you want.

EDIT: Misread that. Here's the link to the thread. Pastebin link is in the main post.

Edited by faubiguy, 07 December 2012 - 06:33 PM.


#6 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

Posted 07 December 2012 - 06:28 PM

Where?

I really want to play it.

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 December 2012 - 09:08 PM

APIs serve an extremely valuable role. By separating out re-usable code into a separate file, one can allow many programs to use those functions without needing to have them explicitly in their own code. By centralizing these functions, you can gain vast improvements "for free", because when you update the API, all of the programs that use it gain the new functionality. When you have an API interface, your program no longer needs to know explicit details of what it's interacting with; if it knows what to pass to the API functions and what to expect back, the intermediate details become irrelevant.

None of these are feasible when you include every function you'll need for a program explicitly in that program. Imagine having to copy and paste read() into every single program you wrote in order to let it take user input with it. APIs certainly have their place.

I think your complaint is much more about the lack of an auto-installer than about the use of APIs.

#8 BigSHinyToys

  • Members
  • 1,001 posts

Posted 07 December 2012 - 11:13 PM

View Postwalia6, on 07 December 2012 - 05:42 PM, said:

Hey guys,
I was looking for games and I saw the perfect game. TETRIS! But turns out you HAVE TO INSTALL API'S. Why not just make it a program anyway? Its as easy as putting shell.run("APIName") at the top of your code! And its technically less work because you dont have to write the API in functions. for example let's pretend a API with the name of BobTheBuilder (I know its a stupid name but were pretending) then every function would have to be BobTheBuilder.functionName() but by using a program its just functionName().
Please share this with a lot of people so we can stop needing to install API's!
APIS can be a pain to use if you only want them on one computer not all computers just to ues some one else's application. the solution is to make a program that loads the apis on that specific computer and not on all.

This program should be named startup also you must have a folder called apis on the root of the computer you can edit the directory location in the code. I use this so i can play shipper without needing the art API installed in the global APIS directory.
local apiDirectory = "/apis"
if fs.exists(apiDirectory) and fs.isDir(apiDirectory) then
    local tFileList = fs.list(apiDirectory)
    for k,v in pairs(tFileList) do
	    write("Loading : "..v.." ")
	    local test,result = os.loadAPI(apiDirectory.."/"..v)
	    if test then
		    print("success")
	    end
    end
else
    print("ERROR : cant find ",apiDirectory," Directory")
end


#9 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 08 December 2012 - 02:30 AM

i have a ton of apis that do specific things
thats also why i rarely post any code
so i dont have to force people to install my apis

im going to make a program that compiles a program and api together (without extracting)

#10 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 08 December 2012 - 03:02 AM

Or you can do an auto-installer. It's easy for the coder and for the user :) And you can use every a API you need because the user just have to run and download one file :P

#11 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 08 December 2012 - 03:09 AM

View Postbjornir90, on 08 December 2012 - 03:02 AM, said:

Or you can do an auto-installer. It's easy for the coder and for the user :) And you can use every a API you need because the user just have to run and download one file :P
bah, i already have one auto downloading everything from my github

personally i hate programs that extract a ton of stuff just to run a single program
its much much less convenient then just including the used functions in the top of your code

#12 BigSHinyToys

  • Members
  • 1,001 posts

Posted 08 December 2012 - 03:16 AM

View Postbjornir90, on 08 December 2012 - 03:02 AM, said:

Or you can do an auto-installer. It's easy for the coder and for the user :) And you can use every a API you need because the user just have to run and download one file :P
That is one option but requires the HTTP api be on and not every client know how to do that.

#13 billysback

  • Members
  • 569 posts

Posted 08 December 2012 - 05:12 AM

For this TETRIS example faubiguy used two API's, my CGE API (821 lines) and his Menu API (211 lines)
If we was just to copy the functions of the API's to the top of his program he would be adding 1032 lines on top of the code that he used, this is just unnecessary and makes things untidy.

APIs can also be made by other people in order to make other peoples programs easier to make, on top of this is obviously makes the program more readable and tidy.

No offense, but this is such a ridiculous thread.

#14 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

Posted 08 December 2012 - 04:30 PM

Well How do you install an API on a server than? Im not owner?

#15 GopherAtl

  • Members
  • 888 posts

Posted 08 December 2012 - 04:50 PM

apis on these forums are almost never intended to go in the server's rom directory anyway.

os.loadAPI("apiname") loads an api.

Many of us who make and use a lot of apis have startup files taht load them all for us, like the code BigSHinyToys posted earlier in this thread. Then it's a non-issue; apis on a computer go into the apis directory, and they reload every time the computer boots up.

#16 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 09 December 2012 - 08:36 AM

You can do API's however you want. Although loadAPI may be "bullshit" for you, for most purposes it works. Hence the built in API's working. But we don't enforce any method of doing things on you - do things how you like, that's the beauty of being able to code your own stuff.

#17 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 09 December 2012 - 08:48 AM

View PostMechaTallon, on 09 December 2012 - 08:39 AM, said:

:P lol it is bullshit, but it is necessary for the way BIOS loads things (at the current moment anyways).

Whatever. It works, so how is it bullshit? Of course, I'd love to hear some constructive feedback, but I doubt very much it will be forthcoming. The only thing that I think is missing right now is metatables in API's - but that is something I plan to rectify.

#18 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 09 December 2012 - 09:01 AM

View PostMechaTallon, on 09 December 2012 - 08:50 AM, said:

:P lol I say its bullshit that we need another file just to os.loadAPI, I'd much rather just loadAPI from a string. :) That way I don't need users to install more and more programs when they can easily get it through one program.

Well would be easy to create that yourself :P

#19 ChaddJackson12

  • Members
  • 264 posts

Posted 09 December 2012 - 09:23 AM

I agree, API's are really a pain. Because I can never get them to work :l

#20 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 09 December 2012 - 09:29 AM

View PostChaddJackson12, on 09 December 2012 - 09:23 AM, said:

I agree, API's are really a pain. Because I can never get them to work :l

Then that's your problem. There are many examples on how to use API's and a help section.

It just occurred to me - if you want to load an API from a string you might as well just include it in the program.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users