Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts #3049

Closed
gbracha opened this issue May 14, 2012 · 10 comments
Closed

Contracts #3049

gbracha opened this issue May 14, 2012 · 10 comments
Labels
area-language New language issues should be filed at https://github.com/dart-lang/language closed-obsolete Closed as the reported issue is no longer relevant P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@gbracha
Copy link
Contributor

gbracha commented May 14, 2012

See Eiffel for an example of core language support, C#/.NET and Java (including http://go/cofoja developed at Google) for less pretty but fully functional implementations.

This is a complex feature, filing now so it can be considered at the appropriate time.

(It might appeal to the people who have been asking for non nullable types.)

The major pieces that are needed are:

  1. Tagging with predicates
    1.1 Tagging of classes with predicates: invariants
    1.2 Tagging of methods with predicates: preconditions, postconditions, (exceptional postconditions)
  2. New keywords or functions for use in postconditions
    2.1 "result" refers to the method result
    2.2 "old(foo)" refers to the value of foo on method entry
  3. Contract evaluation at runtime: execute before and after method invocations
    3.1 But not when evaluating a contract predicate
    3.2 With facility to enable/disable contracts by library
    3.3 With invariants ignored for "private" method calls (whatever this means for Dart)
    3.4 Inheriting contract predicates from superclasses, interfaces
  4. A way to disable contracts and have the code execute as quickly as if there were no contracts
@gbracha
Copy link
Contributor Author

gbracha commented May 14, 2012

The feature was requested by David Morgan; I am generally sympathetic in principle, but do nor expect this to happen for some time (if ever). It is a complex topic.


Added this to the Later milestone.

@gbracha
Copy link
Contributor Author

gbracha commented May 14, 2012

Added Area-Language label.

@DartBot
Copy link

DartBot commented May 15, 2012

This comment was originally written by dave...@gmail.com


Thanks for filing on my behalf.

The full link for cofoja is http://code.google.com/p/cofoja/

@DartBot
Copy link

DartBot commented Aug 9, 2012

This comment was originally written by IanDavidKe...@gmail.com


This was for many years in the top 25 RFE for Java (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4449383).

Contracts can quickly become very complex and perhaps there's a law of diminishing returns, but they have a good deal of value.

All code has a contract. Most code has an implicit contract: this means a reader must READ THE CODE (all of it) to understand what it does. This makes for much lower productivity in the long-run.

DbC just makes the contract explicit rather than relying upon
a) JavaDoc (etc) comments which are prone to becoming out-of-date or
b) unit-tests which are separate too and often densely written (lack of clarity).
c) reading the code top-to-bottom

My experience of DbC has interesting parallels with unit-testing in that they both result in the developer writing smaller, tighter classes.

Another useful benefit of DbC is that static analysis tools can make a much more reasonable analysis.

If DbC doesn't happen (as I expect it won't), then Dart should at least add non-null types (http://code.google.com/p/dart/issues/detail?id=22).

Source code expressing correctness is a good thing.

This link outlines DbC: http://www.eiffel.com/developers/design_by_contract.html

@DartBot
Copy link

DartBot commented May 14, 2013

This comment was originally written by kevin...@gmail.com


Maybe some simple way to mark type annotations and asserts as part of library api contract - which are used in production mode:

@contract int test(int x) {
   @­contract assert (x > 1 && x < 100);

}

@DartBot
Copy link

DartBot commented Dec 10, 2013

This comment was originally written by ronag89...@gmail.com


Library based solution? https://groups.google.com/a/dartlang.org/forum/?fromgroups#!topic/misc/w02qkmFYqE0

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@gbracha
Copy link
Contributor Author

gbracha commented Jan 2, 2015

Issue #15390 has been merged into this issue.

@gbracha gbracha added Type-Enhancement area-language New language issues should be filed at https://github.com/dart-lang/language labels Jan 2, 2015
@gbracha gbracha self-assigned this Jan 2, 2015
@chalin
Copy link
Contributor

chalin commented Sep 29, 2015

FYI. The addition of native C# support for method contracts was discussed at the Jan 21, 2015 C# Design Meeting. The issue used to track this specific feature is dotnet/roslyn#119.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
dart-bot pushed a commit that referenced this issue Sep 13, 2021
New commits in this version:

git -C third_party/pkg/pub log --oneline cd7a43f2109f7e5eb22e73c7f4e15d25fd57598e..d95c5713dda518ed53ada70e00789e6aadbfbe48
d95c5713 (HEAD, origin/master, origin/HEAD) Remove duplicate global invocation on Windows (#3055)
4c5198df master->main (#3101)
e793fd52 More tool/test.dart tweaks (#3097)
1b228edd Report retracted packages (#3093)
4fedb6c5 Tweak strict dependencies error message for `_validateBenchmarkTestTool` (#3087)
e608ab6e Improve test script (#3091)
abf702c4 Detect potential leaks in `dart pub publish`. (#3049)
9941c1f9 Fix broken simplification of prerelease constraints (#3078)
f0cdfa27 format (#3086)
5a1242c6 Fix unicode terminal detection windows (#2933)
58e2296d Dart format (#3084)
1426601c use incremental compilation in the tool/test.dart script (#3075)
9954f851 Fix a typo (#3062)
44489b31 Use relative import for path.dart (#2959)
77702ab1 Always precompile scripts before running them (#3074)

Change-Id: I913ab9e3b5bc7181d483a2de96ec4ad917028b75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213262
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
copybara-service bot pushed a commit that referenced this issue May 24, 2022
…3 revisions)

https://dart.googlesource.com/dartdoc/+log/c58f21042ebd..8549817bb1b5

2022-05-24 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 3 to 3.0.2 (#3048)
2022-05-24 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 1.0.26 to 2.1.11 (#3049)
2022-05-24 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 3.0.0 to 3.1.0 (#3050)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/dart-doc-dart-sdk
Please CC dart-ecosystem-gardener@grotations.appspotmail.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Dart Documentation Generator: https://github.com/dart-lang/dartdoc/issues
To file a bug in Dart SDK: https://github.com/dart-lang/sdk/issues

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

Tbr: dart-ecosystem-gardener@grotations.appspotmail.com
Change-Id: I14041ce5576cc0efadcc897603f8b7893b891b22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245721
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: DEPS Autoroller <dart-autoroll@skia-public.iam.gserviceaccount.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language New language issues should be filed at https://github.com/dart-lang/language closed-obsolete Closed as the reported issue is no longer relevant P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants