Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C71BF200D16 for ; Tue, 10 Oct 2017 21:45:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C5AA0160BE0; Tue, 10 Oct 2017 19:45:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1777F1609CB for ; Tue, 10 Oct 2017 21:45:23 +0200 (CEST) Received: (qmail 70015 invoked by uid 500); 10 Oct 2017 19:45:23 -0000 Mailing-List: contact dev-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list dev@geode.apache.org Received: (qmail 70002 invoked by uid 99); 10 Oct 2017 19:45:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Oct 2017 19:45:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 28994D9C15 for ; Tue, 10 Oct 2017 19:45:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.48 X-Spam-Level: ** X-Spam-Status: No, score=2.48 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=pivotal-io.20150623.gappssmtp.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 5dURWSzIgmLI for ; Tue, 10 Oct 2017 19:45:20 +0000 (UTC) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com [209.85.215.48]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 5E8E15F121 for ; Tue, 10 Oct 2017 19:45:20 +0000 (UTC) Received: by mail-lf0-f48.google.com with SMTP id a16so14896441lfk.0 for ; Tue, 10 Oct 2017 12:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pivotal-io.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=ey2hGUFiOX3XAcqmy/tC1QMdKFl8veyHOORT22h9Fmk=; b=ER+uv/fgwiKQEUtFNS0lpQzKjFHim6eOa1s9jA/xzxtsJaJlryZA6EmwFZ9YseOQya ebQJdXLmJUhrAbAcUXaweBYeWTHC3Dct02ibJ6VDfukB/6oUrh8JlZIqrZ+yUxRlfRaV X3AisDbstcmx9kG/dRDM0Sq7fKPSi03GdJYLWai6L8suQPwzsd88UEU+PkLZLmJ2gUdX sUOZNcn2YuINwvO12ggJUDp60KxXZCNADHEOfbOUNQ9Ngi4dqpsOi2CRSk4IfLMWzgZc ATF1Jy6uJo9Nnvnv+tGZ73JFDmz3abHwm/ZjvCoGGyIrHUfqJGgWAF014qgUlldHap3R pLGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=ey2hGUFiOX3XAcqmy/tC1QMdKFl8veyHOORT22h9Fmk=; b=dh9rvD+PamLKr7SH3JwSKrWD1W/MrzUkxxyDNrxYRaZ2mBe3O/UGYdkllwfqqVA2ws cy+xC0jvFSmtKZshRTpbDukHovlKgp76iHT2ivTUeDyPTLRIu1LA8nozcq2WVSM5fRU/ /UNzH8pIXzQpRuTs786ChKo4bPGJ7PMdQsyr7V66cE8IDna7wWS8HeXa6f3TaycHfaYU pv6/xEihJhTfEQjaWVTi6BRoW9ZBnlogxxVhnxLBuh5REdkaw6rtn0Zj45/Mt/MRRNht YLvIqqhkakskRYvQk7klAj9L6sBBpFy3D2klHiwY0iJAFBULDFdIY7XaeM6vIO6ufwGk E45A== X-Gm-Message-State: AMCzsaXRnU0hNSWUf3S2qIdOyRKb9L/Db92VYmL1qsk/+TF1NAfT+Rlt Mr0tfJpjXU/6jQya7Ngyfid8482KwciMM1Ozp4UveA== X-Google-Smtp-Source: AOwi7QD9rOL0cruzjjkP9khaO5LdahQhofNAHZ/wKgoOBzRl2VNiA8qFIoTz8b8mA8PVBlIhdIvS2tXcYv6uNpRpqDI= X-Received: by 10.25.79.74 with SMTP id a10mr2374413lfk.162.1507664719508; Tue, 10 Oct 2017 12:45:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.25.200 with HTTP; Tue, 10 Oct 2017 12:45:18 -0700 (PDT) In-Reply-To: References: From: David Kimura Date: Tue, 10 Oct 2017 12:45:18 -0700 Message-ID: Subject: Re: [DISCUSS] C++ Returning null values To: dev@geode.apache.org Content-Type: multipart/alternative; boundary="94eb2c1cd2e60c11e2055b368cfa" archived-at: Tue, 10 Oct 2017 19:45:25 -0000 --94eb2c1cd2e60c11e2055b368cfa Content-Type: text/plain; charset="UTF-8" Yes, but I wouldn't expect to ever need to do a type check. Admittedly, I'm not sure what one does with parent region, but if we no-op, return sensible empty values, or throw when appropriate then maybe we don't care? I would expect it to be used something like this: auto parent = region.getParent(); // if region didn't have parent region, this could always return false. // else if it did have a parent region it would behave as expected. parent.containsKey("a_key"); If this works, I like that we don't have to special case for calling getParent on root region and we could return by value. Thanks, David On Tue, Oct 10, 2017 at 12:29 PM, Jacob Barrett wrote: > Are you thinking something like? > > class NoRegion : public Region {...}; > > auto parent = region.getParent(); > if (NoRegion == parent) { > // no parent region > } > > > On Tue, Oct 10, 2017 at 11:08 AM David Kimura wrote: > > > I'm not sure if this is the same as the sentinel value you mentioned, but > > what about introducing a no-op region type and returning that? I'm > > thinking a null object pattern which would no-op and then nobody should > > need to check if nullptr. > > > > Thanks, > > David > > > > On Tue, Oct 10, 2017 at 10:27 AM, Jacob Barrett > > wrote: > > > > > Looking at a class like Region (Region.cpp) there are calls to get the > > > parent region and sub regions, there are instances where a Region will > > not > > > have a parent or subs. The current API returns shared_ptr that may be > > > nullptr or a Region. > > > > > > Since we are trying to make an effort towards values over pointers > should > > > be considered some changes here? Obviously a reference is out of the > > > question because it can't be null. A value is really out of the > question > > > too since it can't be null and making a sentinel value is not a great > > > solution. Raw pointers are fine since they can be nullptr but make > > > ownership ambiguous. Using shared_ptr is good since it can be nullptr > and > > > solves the ownership problem. Another option is to embrace the > > forthcoming > > > std::optional available as boost::optional in C++11. > > > > > > I am leaning towards keeping it shared_ptr since using boost::optional > > > would require users compile with boost. I don't think we should have > > > anything on our API that is not ours of C++11. Requiring third party > > > libraries to compile against our API doesn't fly right by me. > > > > > > Thoughts? > > > > > > --94eb2c1cd2e60c11e2055b368cfa--