Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

conclusion

never mind. the fields are marked as optional in the spec. it was late. sue me.

the q is left for reference


What is coming out:

  {
   "tags": [
    "cakephp",
    "fileupload",
    "file-get-contents"
   ],
   "answer_count": 0,
   "favorite_count": 0,
   "question_timeline_url": "/questions/3078600/timeline",
   "question_comments_url": "/questions/3078600/comments",
   "question_answers_url": "/questions/3078600/answers",
   "question_id": 3078600,
   "owner": {
    "user_id": 371434,
    "user_type": "unregistered",
    "display_name": "Nick",
    "reputation": 1,
    "email_hash": "2960026756b3103492382b68085207bd"
   },
   "creation_date": 1277021683,
   "last_activity_date": 1277021683,
   "up_vote_count": 0,
   "down_vote_count": 0,
   "view_count": 0,
   "score": 0,
   "community_owned": false,
   "title": "How to retrieve contents from a uploaded file."
  }

Missing:

accepted_answer_id;
bounty_amount;
bounty_closes_date;
closed_date;
closed_reason;
migrated;
protected_date;

if these are omitted as nullable you should consider javascript clients that depend on a value to avoid extreme code bloat and performance hits in doing undefined checks on every expected field.

and if they are being omitted as nullable, why then are not the other 0 fields being rendered. Don't get me wrong, I want the structure rendered as advertised, just asking the logical next question.

share|improve this question
    
Yes, please send me some NULLs (None or ""). –  Dennis Williamson Jun 20 '10 at 14:22
2  
can you PLEASE look at the documentation before you post noise like this, and if you realize after you asked the question could you PLEASE hit the delete button –  Matt S. Jun 20 '10 at 17:44
    
...and cut out the stupid tags. –  Nathan Osman Jun 20 '10 at 18:51
    
@matt i would feel safe in saying that I have spent more time studying the documentation of this api than anyone else in this conversation. the post is not noise, it will remain as reference to anyone else who may have the same question. You might notice the mea culpa. I have no problem admitting when i am wrong. it is call strong opinions weakly held. if you don't like my noise to signal ratio you can start a petition to have me banned. –  Sky Sanders Jun 20 '10 at 19:20
    
@geo - get a grip. –  Sky Sanders Jun 20 '10 at 19:20
    
@code I'm not saying you should be banned. Some of your questions are valid, however, I do not tolerate posts who's answer is in the documentation. Also, saying that you have spend more time studying the documentation just tells me you think you are the best at the API, which I think is a little egotistic. I think you should grow up and realize that some people here don't really like you that much because you are immature. Things in the current API are there for a reason, either because they were there or because somebody requested it when it was in the private beta. –  Matt S. Jun 20 '10 at 21:35
    
@code: I'd be careful - I got a suspension on one of the other StackExchange sites for silly tags. –  Nathan Osman Jun 20 '10 at 22:21
    
@matt - i don't see any subjective comparison of my aptitude with the api to anyone else anywhere in my comments. not sure where you came up with that but since you bring it up, let me be clear: i have spent hundreds of hours personally and directly analyzing the api. I did this in the interest of writing code that correctly reads the API and directly generates source code for a viable wrapper in javascript, .net, silverlight and mono. Added to that I have written hundreds of unit tests directly against the API. That is my perspective. As far as your diatribe regarding immaturity... huh? –  Sky Sanders Jun 20 '10 at 22:29
    
@geo - dude, if i remember correctly, you were warned more than 10 times by moderators to cut it out and if i remember correctly you were just being silly and creating ridiculous tags. dev-brain-fart is a quite applicable and concise tag for this post. i tried to named it never-mind-my-bad-i-dont-know-what-i-was-thinking-thanks-for-helping-me-arrive-‌​at-a-clear-understanding but it kept getting rejected. –  Sky Sanders Jun 20 '10 at 22:32
    
@matt - you have a total of 7 posts with a net rep gain of <200 as evaluated by your peers. normally i have no use for these virtual numbers, but when you start calling my active participation in this 'community' noise and publicly judging me i am just going to have to call you out. "I hate immature people on stackapps" seriously? I almost have to believe your profile when it says that you are 11. With all that said, I am over it. See you in the next Q. –  Sky Sanders Jun 20 '10 at 22:56
    
@code. Please stop being immature. Judge people by their code and their programs, not arbitrary values like net rep gain and hours viewing the api documentation. Please grow up. And also, it says 11 on my profiles for "poops and giggles" –  Matt S. Jun 20 '10 at 23:11
    
@code: I'm not saying I was right to retag, but it certainly wasn't 10 times, and the warnings were posted in a completely different post so I didn't even see them. –  Nathan Osman Jun 20 '10 at 23:13
    
@matt - you seem to be in a crisis of perspective. what say we drop this for now and then at a later date, if it matters, you can come on back and read the comment stream with a set of fresh eyes. i will be happy to pick up then. peace. –  Sky Sanders Jun 20 '10 at 23:23
add comment

1 Answer 1

up vote 1 down vote accepted

There's a distinction to be made between fields that are empty and those with a default value.

score, for instance, is by default 0. It always has a value, conceptually anyway, so it is never omitted.

accepted_answer_id is empty by default. Thus it is not returned, rather than filled with a 0 or -1 or whatever.

I'd also point out that its basically exactly the same amount of code in javascript to check against a default value and the absence of a value.

if(question.accepted_answer_id == -1) ...

versus

if(question.accepted_answer_id == undefined) ...

Our current scheme is slightly better in terms of bandwidth, and much better in terms of conceptual integrity. Omitted fields in a return are undefined fields on the server object.

share|improve this answer
    
actually, you could have saved bandwidth and just told me to open my eyes and see that they are clearly marked required:false ;-) but your assertion about the amount of code required to properly guard against undefined is a bit naive and the code you provide is a vector for very subtle bugs. just sayin. –  Sky Sanders Jun 20 '10 at 17:35
    
@code poet - such as? –  Kevin Montrose Jun 20 '10 at 17:49
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .